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

Commit

Permalink
[Bitstamp] Fix order completion detection & balance reading during op…
Browse files Browse the repository at this point in the history
…en order. (#903)

* Map order completion response from bitstamp (Finished) to one that zenbot is looking for (done). Fixes issue #901.

* • Fix currency = 0 while limit order is open at bistamp.
• Fix “sell order completed at Invalid date:” message on bitstamp order completion.
• Fix #901 preventing recognition of order completion on bitstamp.
  • Loading branch information
tiagosiebler authored and DeviaVir committed Dec 18, 2017
1 parent d56c710 commit 8db9878
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions extensions/exchanges/bitstamp/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,21 @@ module.exports = function container (get, set, clear) {
if (body.status === 'error') {
return retry('getBalance', args)
}
var balance = {asset: 0, currency: 0}
var balance = {
asset: '0',
asset_hold: '0',
currency: '0',
currency_hold: '0'
}

// Dirty hack to avoid engine.js bailing out when balance has 0 value
// The added amount is small enough to not have any significant effect
balance.currency = n(body[opts.currency.toLowerCase() + '_available']) + 0.000001
balance.asset = n(body[opts.asset.toLowerCase() + '_available']) + 0.000001
balance.currency_hold = 0
balance.asset_hold = 0
if (typeof balance.asset == undefined || typeof balance.currency == undefined ) {
balance.currency = n(body[opts.currency.toLowerCase() + '_balance']) + 0.000001
balance.asset = n(body[opts.asset.toLowerCase() + '_balance']) + 0.000001
balance.currency_hold = n(body[opts.currency.toLowerCase() + '_reserved']) + 0.000001
balance.asset_hold = n(body[opts.asset.toLowerCase() + '_reserved']) + 0.000001

if (typeof balance.asset == undefined || typeof balance.currency == undefined) {
console.log('Communication delay, fallback to previous balance')
balance = lastBalance
} else {
Expand All @@ -263,6 +270,7 @@ 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) {

body = statusErr(err,body)
if (body.status === 'error') {
return retry('cancelOrder', func_args, err)
Expand Down Expand Up @@ -290,6 +298,7 @@ module.exports = function container (get, set, clear) {
// 'In Queue', 'Open', 'Finished'
body.status = 'done'
}

orders['~' + body.id] = body
cb(null, body)
})
Expand Down Expand Up @@ -320,12 +329,17 @@ module.exports = function container (get, set, clear) {
var func_args = [].slice.call(arguments)
var client = authedClient()
client.order_status(opts.order_id, function (err, body) {

body = statusErr(err,body)
if (body.status === 'error') {
body = orders['~' + opts.order_id]
body.status = 'done'
body.done_reason = 'canceled'
}
} else if(body.status === 'Finished')
body.status = 'done';

if(body.datetime) body.time = body.datetime;

cb(null, body)
})
},
Expand Down

0 comments on commit 8db9878

Please sign in to comment.