DeviaVir / zenbot

Zenbot is a command-line cryptocurrency trading bot using Node.js and MongoDB.
MIT License
8.23k stars 2.03k forks source link

Buy will not execute if last successful trade was also a buy, sells work fine #1389

Closed ShawnHarte closed 6 years ago

ShawnHarte commented 6 years ago

System information

Describe the problem

Zenbot will trade perfectly as long as it follows the buy...sell...buy pattern, however, I would like it to buy if there is a price improvement and it will not do this, for example sell...buy...buy...sell. It will however, sell...sell...buy. I would like to use 50% percent of the currency balance to buy the asset, and I do not have a problem with it buying ever smaller 50% chunks of the balance, this is the desired behavior. However, it buys with 50% and will not execute another buy until a sell has succeeded. Multiple sell works just fine, and it will sell down until the minimum has been reached. Buys will also buy until the balance remaining is too small, but only if it keeps selling between buys. I also can not trigger a manual buy if the last executed trade was a buy, no errors occur in debug and it seems the request is simply ignored.

Short of it, I would like to know why the bot will not perform 2 or more buys in a row if the price improves and triggers another buy signal.

The sim and backtester, both work as though multiple buys occurred in a row, without a sell to separate them.

This occurs with any strategy, or USD-asset pair on gdax, though it honestly seems as though it will occur with any live trade scenario.

Source code / logs

./zenbot trade gdax.LTC-USD --buy_pct 50 --sell_pct 50 Debug provides no information or errors. The bot will not buy if the last signal that succedded in trading was a buy. It will also not allow a manual buy in the same scenario, the request is ignored silently. Multiple sells can succeed in a row, and a manual sell trade can be executed after a successful sell.

defkev commented 6 years ago

I am not aware of any limitation preventing the bot from executing consecutive buys as long as the strategy tells him to, and your balance allows it of course.

I'd rather trade big orders instead of small once though, otherwise the fees might eat up your revenue.

Just out of curiosity, what happens if your change buy_pct to less than 50, e.g. 25?

ShawnHarte commented 6 years ago

You've nailed the exact reason I posted the question in the first place, I can't find anything anywhere in the code that would keep it from buying again. If I change it to a higher or lower value for buy_pct it will only buy once at whatever that percentage is then wait for a sell to complete before it buys again.

I'm not worried about the fees as they are 0 on gdax maker orders. Currently I'm running with a mildly profitable setup, but it would be more profitable if it would buy on the dips that plateau and then drop a bit more.

Here's a scenario, with what happens and what I would expect to happen with buy_pct & sell_pct 50. Asset Price:.....Balance:......Signal:.....Asset Balance: $100..................$1000..........Buy...........0 $100....................$500........... ............5 $50....................$500...........Buy...........5 I would expect it to buy and have $250 with 10 asset $100....................$750...........Sell............2.5 $200..................$1000...........Sell............1.25 This works as expected

It will do this every time no matter what settings I adjust, and it's driving me absolutely batty. Of course the scenario is fictional, but, I hope it illustrates the problem I'm having.

defkev commented 6 years ago

I am almost (almost) 100% certain i've seen at least one of my bots perform multiple consecutive buys in the past.

Enable --debug and see if it produces any meaningful output, e.g. cancel order or something as this sounds really odd.

ShawnHarte commented 6 years ago

debug shows nothing at all, not even the order status message it normally shows during a buy. The second buy signal shows up, at what seems to be an appropriate time, and the signal doesn't change to null or sell but it never executes the order. It just continues along until a sell signal, then everything works until it wants to buy after a buy.

juosma commented 6 years ago

hi, looks mine issue are connected to these as well. Just i not thought that problem is several "buys" in the row.

https://github.com/DeviaVir/zenbot/issues/1352

linhSUTD commented 6 years ago

I got the same issue with gdax.LTC-USD. After the first successful buy order, I cannot make any buy order anymore. I am running under manual mode.

2018-02-26 15:37:37 217.990 LTC-USD +0.12% 2 11.61364840 LTC 2562.65 USD -1.24% -1.78% 2018-02-26 15:37:48 218.120 LTC-USD +0.05% 4 11.61364840 LTC 2562.65 USD -1.21% -1.81% 2018-02-26 15:37:49 218.170 LTC-USD +0.02% 38 11.61364840 LTC 2562.65 USD -1.20% -1.82% 2018-02-26 15:37:49 217.920 LTC-USD -0.12% 1 11.61364840 LTC 2562.65 USD -1.25% -1.76% manual limit BUY command executed 2018-02-26 15:37:49 217.920 LTC-USD -0.12% 1 11.61364840 LTC 2562.65 USD -1.25% -1.76% 2018-02-26 15:37:51 217.920 LTC-USD +0.00% 0 11.61364840 LTC 2562.65 USD -1.25% -1.76% 2018-02-26 15:37:54 217.940 LTC-USD +0.00% 11 11.61364840 LTC 2562.65 USD -1.25% -1.77% 2018-02-26 15:38:01 217.950 LTC-USD +0.00% 14 11.61364840 LTC 2562.65 USD -1.25% -1.77% 2018-02-26 15:38:02 217.940 LTC-USD -0.01% 12 11.61364840 LTC 2562.65 USD -1.25% -1.77% 2018-02-26 15:38:06 218.000 LTC-USD +0.02% 4 11.61364840 LTC 2562.65 USD -1.24% -1.78% 2018-02-26 15:38:07 218.000 LTC-USD +0.00% 0 11.61364840 LTC 2562.65 USD -1.24% -1.78% 2018-02-26 15:38:09 218.000 LTC-USD +0.00% 6 11.61364840 LTC 2562.65 USD -1.24% -1.78% 2018-02-26 15:38:13 218.000 LTC-USD +0.00% 0 11.61364840 LTC 2562.65 USD -1.24% -1.78% 2018-02-26 15:38:14 217.980 LTC-USD -0.01% 9 11.61364840 LTC 2562.65 USD -1.24% -1.78%

ShawnHarte commented 6 years ago

I'm inclined to think it's a bug somewhere, however, I can not pin down what exactly is happening to cause it not to buy. There is no debug message, no error message, and nothing in the code anywhere that specifically seems to restrict or prevent a buy following a successful buy trade. On a side note, I discovered an a couple issues with the wavetrend strategy as well, so I'll have to write up another issue for that. The changes do not solve this problem, sadly.

stinkyjames commented 6 years ago

Just change held_pct to 0 in engine.js and it will buy and sell all day with multiple buys when it meets your conditions without waiting for a sell to be triggered, but beware, when it does sell, it will only reference the last buy price. There is currently no first-in last-out on the buy_price.

ShawnHarte commented 6 years ago

That's exactly the setting I was looking for, and that works for me. I'll let this sit open for a day or 2 to make sure it works for others. Thanks a million!