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

Placing buy, then cancelling order, confuses Zenbot into thinking you still have funds held #1284

Open
glennfu opened this issue Feb 5, 2018 · 1 comment

Comments

@glennfu
Copy link
Contributor

glennfu commented Feb 5, 2018

order.size is calculated like this:

size = n(s.balance.currency).multiply(buy_pct).divide(100).multiply(s.exchange.makerFee / 100).format('0.00000000')

Then later on in cancelOrder, you have:

order.remaining_size = n(order.size).subtract(api_order.filled_size).format('0.00000000')
on_hold = n(s.balance.currency).subtract(s.balance.currency_hold || 0).value() < n(order.price).multiply(order.remaining_size).value()

So in my case of trading EOS, with 0.0089 BTC. I place a buy order in for 8 EOS at a rate of 0.00107725. Zenbot computes order.size as 8.32426980 because of the maker fee inflation in that first calculation. When I'm cancelling the order, it's saying currency - currency_hold > price * remaining_size which looks like 0.0089 - 0 < 0.00107725 * 8.32426980 => 0.0089 < 0.008967319642.

This incorrectly tells Zenbot you have funds held, when the calculation SHOULD read: 0.0089 - 0 < 0.00107725 * 8 => 0.0089 < 0.008618 because 8 is the ACTUAL size in that order.

So now even though I have no active orders, and my balance looks like: {"asset":0,"currency":0.0089,"currency_hold":0,"asset_hold":0}, it thinks I have currency held. Then it spits out funds on hold after cancel, waiting 5s forever until I restart Zenbot.

I know it's trying to take into account the fact that you may have multiple orders... but why doesn't the calculation just say on_hold = s.balance.currency_hold > 0?

@glennfu
Copy link
Contributor Author

glennfu commented Feb 5, 2018

Temporary workaround:

// Change this:
if (on_hold) {
  // wait a bit for settlement
  msg('funds on hold after cancel, waiting 5s')
  setTimeout(checkHold, c.wait_for_settlement)
}
else {
  cb(null, do_reorder ? null : false)
}

// To this:
if (on_hold && s.balance.currency_hold > 0) {

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants