diff --git a/extensions/exchanges/binance/exchange.js b/extensions/exchanges/binance/exchange.js index d332f78104..855c588e02 100644 --- a/extensions/exchanges/binance/exchange.js +++ b/extensions/exchanges/binance/exchange.js @@ -25,8 +25,15 @@ module.exports = function container (get, set, clear) { return authed_client } + /** + * Convert BNB-BTC to BNB/BTC + * + * @param product_id BNB-BTC + * @returns {string} + */ function joinProduct(product_id) { - return product_id.split('-')[0] + '/' + product_id.split('-')[1] + let split = product_id.split('-'); + return split[0] + '/' + split[1] } function retry (method, args, err) { @@ -130,8 +137,22 @@ module.exports = function container (get, set, clear) { client.cancelOrder(opts.order_id, joinProduct(opts.product_id)).then(function (body) { if (body && (body.message === 'Order already done' || body.message === 'order not found')) return cb() cb(null) - },function(err){ - if (err) return retry('cancelOrder', func_args, err) + }, function(err){ + // match error against string: + // "binance {"code":-2011,"msg":"UNKNOWN_ORDER"}" + + if (err) { + // decide if this error is allowed for a retry + + if (err.message && err.message.match(new RegExp(/-2011|UNKNOWN_ORDER/))) { + console.error(('\ncancelOrder retry - unknown Order: ' + JSON.stringify(opts) + " - " + err).cyan) + } else { + // retry is allowed for this error + + return retry('cancelOrder', func_args, err) + } + } + cb() }) },