From 9d3b36214eb19d5b871d0e3f33e8d701fe5dde73 Mon Sep 17 00:00:00 2001 From: nedievas Date: Wed, 18 Oct 2017 21:42:46 +0300 Subject: [PATCH 1/4] CEXIO balance and incorrect nonce bugfix balance undefined and nonce error crash fix. Should fix #641 issue. --- extensions/exchanges/cexio/exchange.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/extensions/exchanges/cexio/exchange.js b/extensions/exchanges/cexio/exchange.js index 8b126079a9..cb2d08e662 100644 --- a/extensions/exchanges/cexio/exchange.js +++ b/extensions/exchanges/cexio/exchange.js @@ -19,7 +19,9 @@ module.exports = function container (get, set, clear) { if (!c.cexio || !c.cexio.username || !c.cexio.key || c.cexio.key === 'YOUR-API-KEY') { throw new Error('please configure your CEX.IO credentials in ' + path.resolve(__dirname, 'conf.js')) } + var nonce = Math.floor(new Date().getTime() / 1000) authed_client = new CEX(c.cexio.username, c.cexio.key, c.cexio.secret).rest + authed_client.nonce = function () { return nonce++ } } return authed_client } @@ -72,11 +74,11 @@ module.exports = function container (get, set, clear) { var func_args = [].slice.call(arguments) var client = authedClient() client.account_balance(function (err, body) { - if (err || typeof body === 'undefined') return retry('getBalance', func_args, err) + if (err || typeof body === 'undefined' || body === 'error: Nonce must be incremented') return retry('getBalance', func_args, err) var balance = { asset: 0, currency: 0 } - balance.currency = n(body[opts.currency].available).format('0.00000000') + balance.currency = n(body[opts.currency].available).add(body[opts.currency].orders).format('0.00000000') balance.currency_hold = n(body[opts.currency].orders).format('0.00000000') - balance.asset = n(body[opts.asset].available).format('0.00000000') + balance.asset = n(body[opts.asset].available).add(body[opts.asset].orders).format('0.00000000') balance.asset_hold = n(body[opts.asset].orders).format('0.00000000') cb(null, balance) }) @@ -96,7 +98,6 @@ module.exports = function container (get, set, clear) { var func_args = [].slice.call(arguments) var client = authedClient() client.cancel_order(opts.order_id, function (err, body) { - if (body === 'Order canceled') return cb() if (err) return retry('cancelOrder', func_args, err) cb() }) @@ -112,7 +113,6 @@ module.exports = function container (get, set, clear) { opts.size = n(opts.size).multiply(opts.orig_price).value() // CEXIO estimates asset size and uses free currency to performe margin buy opts.type = 'market' } - delete opts.order_type client.place_order(pair, 'buy', opts.size, opts.price, opts.type, function (err, body) { if (body === 'error: Error: Place order error: Insufficient funds.') { var order = { @@ -146,7 +146,6 @@ module.exports = function container (get, set, clear) { delete opts.post_only opts.type = 'market' } - delete opts.order_type client.place_order(pair, 'sell', opts.size, opts.price, opts.type, function (err, body) { if (body === 'error: Error: Place order error: Insufficient funds.') { var order = { @@ -176,7 +175,7 @@ module.exports = function container (get, set, clear) { var order = orders['~' + opts.order_id] var client = authedClient() client.get_order_details(opts.order_id, function (err, body) { - if (err || typeof body === 'undefined') return retry('getOrder', func_args, err) + if (err || body === 'error: Invalid Order ID') return retry('getOrder', func_args, err) if (body.status === 'c') { order.status = 'rejected' order.reject_reason = 'canceled' @@ -184,7 +183,7 @@ module.exports = function container (get, set, clear) { if (body.status === 'd' || body.status === 'cd') { order.status = 'done' order.done_at = new Date().getTime() - order.filled_size = n(opts.size).subtract(body.remains).format('0.00000000') + order.filled_size = n(body.amount).subtract(body.remains).format('0.00000000') } cb(null, order) }) From fe33a6806cb1660184754aa8206ba85a69685d7c Mon Sep 17 00:00:00 2001 From: nedievas Date: Thu, 19 Oct 2017 17:09:09 +0300 Subject: [PATCH 2/4] backfill fix --- extensions/exchanges/cexio/exchange.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/extensions/exchanges/cexio/exchange.js b/extensions/exchanges/cexio/exchange.js index cb2d08e662..edced0605d 100644 --- a/extensions/exchanges/cexio/exchange.js +++ b/extensions/exchanges/cexio/exchange.js @@ -43,6 +43,7 @@ module.exports = function container (get, set, clear) { var exchange = { name: 'cexio', historyScan: 'forward', + backfillRateLimit: 0, makerFee: 0, takerFee: 0.2, @@ -52,11 +53,14 @@ module.exports = function container (get, set, clear) { getTrades: function (opts, cb) { var func_args = [].slice.call(arguments) - var args = opts.from + var args = {} + if (opts.from) { + args = Number(opts.from) + } var client = publicClient() var pair = joinProduct(opts.product_id) client.trade_history(pair, args, function (err, body) { - if (err || typeof body === 'undefined') return retry('getTrades', func_args, err) + if (err || body === undefined || body === 'error: Rate limit exceeded') return retry('getTrades', func_args, err) var trades = body.map(function (trade) { return { trade_id: Number(trade.tid), From 6c6e9a3cbd32ba8a066d87f002114389b7b23477 Mon Sep 17 00:00:00 2001 From: nedievas Date: Mon, 23 Oct 2017 22:36:39 +0300 Subject: [PATCH 3/4] quick and dirty getTrades() fix --- extensions/exchanges/cexio/exchange.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/exchanges/cexio/exchange.js b/extensions/exchanges/cexio/exchange.js index edced0605d..8a2b69dc0b 100644 --- a/extensions/exchanges/cexio/exchange.js +++ b/extensions/exchanges/cexio/exchange.js @@ -53,9 +53,9 @@ module.exports = function container (get, set, clear) { getTrades: function (opts, cb) { var func_args = [].slice.call(arguments) - var args = {} + var args if (opts.from) { - args = Number(opts.from) + args = opts.from } var client = publicClient() var pair = joinProduct(opts.product_id) From bea1d814d216c643c90f5a8a4dce93e8688d2662 Mon Sep 17 00:00:00 2001 From: Chase Date: Wed, 25 Oct 2017 00:58:30 +0200 Subject: [PATCH 4/4] fix nit whitespace --- extensions/exchanges/cexio/exchange.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/exchanges/cexio/exchange.js b/extensions/exchanges/cexio/exchange.js index 8a2b69dc0b..5f43fa82ed 100644 --- a/extensions/exchanges/cexio/exchange.js +++ b/extensions/exchanges/cexio/exchange.js @@ -179,7 +179,7 @@ module.exports = function container (get, set, clear) { var order = orders['~' + opts.order_id] var client = authedClient() client.get_order_details(opts.order_id, function (err, body) { - if (err || body === 'error: Invalid Order ID') return retry('getOrder', func_args, err) + if (err || body === 'error: Invalid Order ID') return retry('getOrder', func_args, err) if (body.status === 'c') { order.status = 'rejected' order.reject_reason = 'canceled'