zenbot icon indicating copy to clipboard operation
zenbot copied to clipboard

[Question] Algorithm to stop buy order attempts

Open cpjolicoeur opened this issue 8 years ago • 14 comments

This is simply a question of a bit of zenbot functionality. I'm trying to piece through the code flow myself to discern some of these things, but haven't' quickly found a solid answer to this yet.

I've had several instances when zenbot has attempted to place a buy order that didn't get filled, that order gets canceled and a new order entered, but that also doesn't get filled. The price continues to rise and zenbot just stops attempting to place new buy orders. This has prevented the bot from taking advantage of several decent run-ups since it was unable to buy.

What (or where in the code) is the logic that would basically have zenbot just "give up" on a buy when a buy signal is triggered. I can't find anywhere that a "number of attempts" is configured that would limit this to a hard number.

Is this related to the various strategy logic directly and the period length? For instance, if my period length is only 2 minutes, will the buy order only be placed during that 2 minute period where the buy was originally triggered? Then future periods dont have any kind of signal and do nothing, even though the previous buy orders failed?

Or do I need to do some manipulation of the order_adust_time and order_poll_time params somehow?

cpjolicoeur avatar Jan 25 '18 14:01 cpjolicoeur

I am not aware of a "give up" logic within the code. The bot does what the strategy tells him to do.

The bot will only cancel an order if the signal switches (buy -> sell -> buy -> ...)

What you describe sounds like the exchange rejecting your open order because the price differs too much from the current market, this will cause zenbot to readjust the order and do a re-order using a price closer to the current market.

Exchanges usually do this to prevent orders which would never get filled from cluttering up the order book.

defkev avatar Jan 25 '18 16:01 defkev

Viewing some of the logging output it appears there are some issues with cancelling and placing new orders.

2018-01-25 11:12:37 - order status: open
2018-01-25 11:12:42 - order status: open
2018-01-25 11:12:47 - order status: open
2018-01-25 11:12:52 - order status: open
2018-01-25 11:12:58 - order status: open
2018-01-25 11:12:58 - 1034.89 vs our 1034.83
2018-01-25 11:12:58 - cancelling order
2018-01-25 11:12:58 - buy order timed out, adjusting price
2018-01-25 11:12:58 - placing buy order...
2018-01-25 11:12:58 - not enough balance for buy, aborting
2018-01-25 11:12:58 - not enough balance, or signal switched, cancel buy

I don't know if this is a result of the buy order being placed with incorrect math? eg. trying to buy more than it can at a given price with the currency available. Or if this is a delay on the API side where the previously cancelled order's funds haven't been "credited" back to my balance yet, so the new buy order fails due to insufficient funds.

cpjolicoeur avatar Jan 25 '18 16:01 cpjolicoeur

The amount the bot trades can be set with --buy_pct and --sell_pct Unless they are set to 100% (not covering possible fees) the bot shouldn't complain about not enough balance

2018-01-25 11:12:58 - not enough balance for buy, aborting

Means the exchange rejected the order due to insufficient funds.

defkev avatar Jan 25 '18 16:01 defkev

Agreed, I'm not sure why the API is reporting insufficient funds.

I have the buy/sell percentages set to 100% and am in Maker-only mode (at GDAX), so there would be no fees involved to be concerned with at a 100% order.

That is why I was thinking maybe there was an API timing issue on GDAX's side where the previously cancelled buy orders funds hadn't been credited to my account by the time the updated buy order was attempting to be placed, resulting in GDAX rejecting the new order and zenbot cancelling the whole process due to the exchange aborting the buy.

cpjolicoeur avatar Jan 25 '18 16:01 cpjolicoeur

I'll try trading at 99% for a bit and see what results as far as order creation success rates.

cpjolicoeur avatar Jan 25 '18 16:01 cpjolicoeur

Would be interesting to know, if this really is a timing issue you should still hit the same problem.

defkev avatar Jan 25 '18 16:01 defkev

Yeah, that was my thinking. If the problem goes away at 99%, then it's not timing issues and it's that the bot isn't really creating POST only (maker) trades every time, and, in that case, trading with 100% would definitely fail as fees couldn't be covered.

cpjolicoeur avatar Jan 25 '18 17:01 cpjolicoeur

I've had a similar problem, I set my percentage at 99.75. on the exchange where I am trading it charges a .25% fee. seems to be working so far.

station384 avatar Jan 25 '18 18:01 station384

I've seen this happen a lot with post only orders on gdax, so i don't think fees are the issue. It seems like when the price slips, the order price gets updated, but not the quantity, so it's trying to buy the same amount for a higher price, hence there are insufficient funds to cover the order when buying 100%.

blevok avatar Jan 25 '18 21:01 blevok

@blevok interesting. That's a theory to go on and investigate for sure. I'll see if I can follow the logic and see if I can confirm/deny that as a possibility in the GDAX code. If it is doing a price adjustment without also trying to adjust the quantity appropriately that would definitely cause problems.

cpjolicoeur avatar Jan 25 '18 21:01 cpjolicoeur

So, after changing my buy/sell percentages to 99% and then 99.75% I haven't had the same issue, so I don't think it's a race condition/timing issue with GDAX's API.

I'll take a look at the re-price/re-buy code to see if maybe there is a logic issue there with placing subsequent orders over the currently available funds amount.

cpjolicoeur avatar Jan 26 '18 14:01 cpjolicoeur

Hi, it seems i have the same issue with this one, hopefully there will be resolution to this. I tried to put 95% for now and will see what impact does it have on the behavior of the BOT

DenMantm avatar Jan 28 '18 10:01 DenMantm

Hi, it seems it is working fine now, if set to 95%, there is enough margin for the error.

DenMantm avatar Feb 09 '18 16:02 DenMantm

Dear issue reporter,

We have slightly changed our github issue policy and would now kindly request folks that have questions that they ask them in our zenbot subreddit.

You can find it here: https://reddit.com/r/zenbot

This issue will be closed, but if you disagree with your ticket being marked as a question feel free to leave a comment defending your case.

Thanks for contributing time and effort!

Greetings, 🤖

DeviaVir avatar Feb 28 '18 12:02 DeviaVir