diff --git a/extensions/exchanges/binance/update-products.sh b/extensions/exchanges/binance/update-products.sh index 9f974f14fb..aae33066bf 100755 --- a/extensions/exchanges/binance/update-products.sh +++ b/extensions/exchanges/binance/update-products.sh @@ -4,44 +4,24 @@ let ccxt = require('ccxt') new ccxt.binance().fetch_markets().then(function(markets) { var products = [] - markets.forEach(function (market) { - var currStepSize = market.info.filters[0].tickSize - for (i = currStepSize.length - 1; i > 0; i--) { - if (currStepSize[i] === '0') - currStepSize = currStepSize.slice(0, i) - else - break; - } - - var assetStepSize = market.info.filters[1].stepSize - for (i = assetStepSize.length - 1; i > 0; i--) { - if (assetStepSize[i] === '0') - assetStepSize = assetStepSize.slice(0, i) - else - break - } + var products = markets.map(function (market) { + const filters = market.info.filters + const price_filter = filters.find(f => f.filterType === 'PRICE_FILTER') + const lot_size_filter = filters.find(f => f.filterType === 'LOT_SIZE') + const notional_filter = filters.find(f => f.filterType === 'MIN_NOTIONAL') - // The MIN_NOTIONAL filter defines the minimum notional value allowed for an order on a symbol. - // An orders notional value is the price * quantity. - // In order to know the Value it is necessary to know the price which does not come on this JSon. - // But I have the maxPrice which seems to be: price * 10 - var maxPrice = Number(market.info.filters[0].maxPrice); - var curPrice = maxPrice / 10; - var minNotional = Number(market.info.filters[2].minNotional); - var minNotionalQty = minNotional / curPrice; - var minQty = Number(market.info.filters[1].minQty); - var min_size = Math.max(minQty, minNotionalQty).toString(); - - products.push({ + // NOTE: price_filter also contains minPrice and maxPrice + return { id: market.id, asset: market.base, currency: market.quote, - min_size: min_size, - max_size: market.info.filters[1].maxQty, - increment: currStepSize, - asset_increment: assetStepSize, + min_size: lot_size_filter.minQty, + max_size: lot_size_filter.maxQty, + min_total: notional_filter.minNotional, + increment: price_filter.tickSize, + asset_increment: lot_size_filter.stepSize, label: market.base + '/' + market.quote - }) + } }) var target = require('path').resolve(__dirname, 'products.json') diff --git a/lib/engine.js b/lib/engine.js index 65d46d981d..b1d2784384 100644 --- a/lib/engine.js +++ b/lib/engine.js @@ -305,6 +305,14 @@ module.exports = function (s, conf) { }) } + function isOrderTooSmall(product, quantity, price) { + if (product.min_size && Number(quantity) < Number(product.min_size)) + return true + if (product.min_total && n(quantity).multiply(price).value() < Number(product.min_total)) + return true + return false + } + // if s.signal // 1. sync balance // 2. get quote @@ -395,7 +403,7 @@ module.exports = function (s, conf) { size = n(trade_balance).subtract(expected_fee).divide(price).format(s.product.asset_increment ? s.product.asset_increment : '0.00000000') } - if ((s.product.min_size && Number(size) >= Number(s.product.min_size)) || ('min_total' in s.product && s.product.min_total && n(size).multiply(price).value() >= Number(s.product.min_total))) { + if (!isOrderTooSmall(s.product, size, price)) { if (s.product.max_size && Number(size) > Number(s.product.max_size)) { size = s.product.max_size } @@ -446,7 +454,7 @@ module.exports = function (s, conf) { } size = n(s.balance.asset).multiply(sell_pct / 100).format(s.product.asset_increment ? s.product.asset_increment : '0.00000000') - if ((s.product.min_size && Number(size) >= Number(s.product.min_size)) || (s.product.min_total && n(size).multiply(price).value() >= Number(s.product.min_total))) { + if (!isOrderTooSmall(s.product, size, price)) { if (s.product.max_size && Number(size) > Number(s.product.max_size)) { size = s.product.max_size }