diff --git a/views/market_view.html b/views/market_view.html index 789011e..9b58cd2 100644 --- a/views/market_view.html +++ b/views/market_view.html @@ -45,6 +45,19 @@

Buy <%= data.token %>

+
+
+
+ +
+ + + + +
+
+
+
@@ -100,6 +113,19 @@

Sell <%= data.token %>

+
+
+
+ +
+ + + + +
+
+
+
@@ -177,8 +203,55 @@

Trade History

function UpdateBuyOrderTotal() { return UpdateOrderTotal('buy') } function UpdateSellOrderTotal() { return UpdateOrderTotal('sell') } + function UpdateQuantity(type, rate) { + var quanity = type === 'buy' ? data.buy_orders[0].quantity : data.sell_orders[0].quantity; + var currentQuantity = parseFloat(quanity); + var newQuantity = currentQuantity * rate; + + $('#' + type + 'Quantity').val(newQuantity.toFixed(data.precision)); + } + + function GetBestPrice(type) { + if (type === 'buy') { + return data.buy_orders[0] && data.buy_orders[0].price || 0; + } + + if (type === 'sell') { + return data.sell_orders[0] && data.sell_orders[0].price || 0; + } + } + + function GetQuantity(type) { + if (type === 'buy') { + return data.buy_orders[0] && data.buy_orders[0].quantity || 0; + } + + if (type === 'sell') { + return data.sell_orders[0] && data.sell_orders[0].quantity || 0; + } + } + console.log(data); + $('#buyPrice').val(() => GetBestPrice('buy')); + $('#buyQuantity').val(() => GetQuantity('buy')); + UpdateBuyOrderTotal(); + + $('#sellPrice').val(() => GetBestPrice('sell')); + $('#sellQuantity').val(() => GetQuantity('sell')); + UpdateSellOrderTotal(); + + $('#buyQty25Percent').on('click', () => UpdateQuantity('buy', 0.25)); + $('#buyQty50Percent').on('click', () => UpdateQuantity('buy', 0.5)); + $('#buyQty75Percent').on('click', () => UpdateQuantity('buy', 0.75)); + $('#buyQty100Percent').on('click', () => UpdateQuantity('buy', 1)); + + $('#sellQty25Percent').on('click', () => UpdateQuantity('sell', 0.25)); + $('#sellQty50Percent').on('click', () => UpdateQuantity('sell', 0.5)); + $('#sellQty75Percent').on('click', () => UpdateQuantity('sell', 0.75)); + $('#sellQty100Percent').on('click', () => UpdateQuantity('sell', 1)); + + $('#buyPrice').on('input', UpdateBuyOrderTotal); $('#buyQuantity').on('input', UpdateBuyOrderTotal); @@ -390,4 +463,4 @@

Trade History

SE.ShowMarketCancelDialog(type, orderId); } - \ No newline at end of file +