Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Fix endless retry in cancelOrder Binance exchange action #1122

Merged
merged 1 commit into from
Jan 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions extensions/exchanges/binance/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
})
},
Expand Down