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

buy fails when buy_pct = 100 #1315

Open
Burnie09 opened this issue Feb 10, 2018 · 7 comments
Open

buy fails when buy_pct = 100 #1315

Burnie09 opened this issue Feb 10, 2018 · 7 comments

Comments

@Burnie09
Copy link
Contributor

Burnie09 commented Feb 10, 2018

System information

  • Have I written custom code (as opposed to using zenbot vanilla): no
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 16.04
  • Zenbot version: unstable
  • NodeJS version: v8.9.4
  • Python version: 2.7.12
  • Exact command to reproduce: buy (maker) - buy_pct = 100

Describe the problem

( GDAX.BTC-EUR / maker )

When zenbot is adjusting a (maker) buy, it adjusts price, but doesn't seem to adjust size to buy.
Having c.buy_pct = 100 will result in not enough funds.
Workaround is using c.buy_pct = 99 (will not work if slippage > ~1.01%)

example below:

  • buy (manual/maker) with 100% of 609.93 EUR
  • puts out a buy for 0.08790594 @ 6938.53 = 609.93 EUR
  • then auto-adjusts it to 0.08790594 @ 6938.69 = 609.95 EUR

Source code / logs

  • added some more verbose output to the debug (size and price)

2018-02-10 16:23:31 6938.79 BTC-EUR +0.11% 2 --- 28.15 -0.0643 0.0243 0.00000 BTC 609.93 EUR +0.00% +1.99%

manual limit BUY command executed
2018-02-10 16:23:42 - placing buy order...
2018-02-10 16:23:42 - buy order placed at 6938.53 EUR
2018-02-10 16:23:44 - order status: open
2018-02-10 16:23:46 - order status: open
2018-02-10 16:23:48 - order status: open
2018-02-10 16:23:50 - order status: open
2018-02-10 16:23:50 - 6938.54 vs our 6938.53
2018-02-10 16:23:50 - cancelling order
2018-02-10 16:23:51 - buy order timed out, adjusting price
2018-02-10 16:23:51 - placing buy order...
2018-02-10 16:23:51 - not enough balance for buy, aborting - 0.08790594 @ 6938.69
2018-02-10 16:23:51 - not enough balance, or signal switched, cancel buy

2018-02-10 16:23:52 6938.79 BTC-EUR +0.11% 2 --- 28.15 -0.0643 0.0243 0.00000 BTC 609.93 EUR +0.00% +1.99%

@defkev
Copy link
Contributor

defkev commented Feb 10, 2018

This is correct and has been reported before.

Unless an order has been partially filled a re-order will always use the same size, which inevitable causes a insufficient funds error if the price moved up.

Looking at the code one possible solution would be to remove the size attribute during a price adjust if the order has not been partially filled, this way executeSignal recalculates the size according to the new price.

@defkev
Copy link
Contributor

defkev commented Feb 10, 2018

PR ready.

Test it and report back @Burnie09

@Burnie09
Copy link
Contributor Author

It seems to be working (added some more debug to check);

2018-02-10 20:16:18 - placing buy order...
2018-02-10 20:16:19 - buy order for 0.08683668 placed at 6866.91 EUR (596.2996662588)

2018-02-10 20:16:17 6862.32 BTC-EUR +0.20% 1 - 49.64 0.0347 0.0196 buying 0.00000 BTC 596.29 EUR

2018-02-10 20:16:22 - 6867.33 vs our 6866.91
2018-02-10 20:16:23 - buy order timed out, adjusting price
2018-02-10 20:16:24 - buy order for 0.08683137 placed at 6867.33 EUR (596.2996721421)

2018-02-10 20:16:34 - 6867.34 vs our 6867.33
2018-02-10 20:16:35 - buy order timed out, adjusting price
2018-02-10 20:16:36 - buy order for 0.08683124 placed at 6867.34 EUR (596.2996477016)
...
2018-02-10 20:17:32 - order status: open
2018-02-10 20:17:32 - 6890.09 vs our 6889.67
2018-02-10 20:17:32 - cancelling order
2018-02-10 20:17:33 - buy order timed out, adjusting price
2018-02-10 20:17:34 - placing buy order...
2018-02-10 20:17:34 - buy order for 0.08654466 placed at 6890.08 EUR (596.2996309728)
2018-02-10 20:17:36 - order status: done

buy order completed at 2018-02-10 20:17:34:
0.08683668 BTC at 6890.08 EUR
total 598.311 EUR
0.3374% slippage (orig. price 6866.91 EUR)
execution: a minute

2018-02-10 20:18:00 6867.75 BTC-EUR -0.28% 2 50.74 + 0.0354 0.0376 bought 0.08654 BTC 0.00 EUR

Seems the size in the completion text is the original size (0.08683668), but it works. - 100% bought.

@defkev
Copy link
Contributor

defkev commented Feb 10, 2018

100% bought

👍

I wonder why we are tracking size as _order.orig_size in my_trades though 🤔

@defkev
Copy link
Contributor

defkev commented Feb 10, 2018

nvm.

If this was a partial order we of course would wont the original size duh

We could change it in placeOrder and (maybe) add a adjusted flag if _order exists.

@defkev
Copy link
Contributor

defkev commented Feb 11, 2018

Thats actually a silly hack as it doesn't account for timed out partial orders.

I'll switch one of my bots to 100% and think of a proper solution once i have the time.

@Burnie09
Copy link
Contributor Author

Just to let you know. I can confirm your findings. Partial orders just stops.
(And then you don't seem to manually buy the rest either.)

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

3 participants