zenbot icon indicating copy to clipboard operation
zenbot copied to clipboard

ZenbotGot stuck at sell price and constantly selling at same price at loss

Open code4passion opened this issue 8 years ago • 24 comments

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
  • Zenbot version: commit f235ba1e3966801b3617ac20c2ac60dcd299e8f6 (HEAD -> master, tag: v4.1.0, origin/master, origin/HEAD) Author: Chase [email protected] Date: Sun Jan 7 02:32:12 2018 +0100 v4.1.0: release to master (#1069)

Strategy user : trend_ema MODE: Paper

Describe the problem

Zenbot was trading fine in paper mode for some initially. But after some time it started selling at exactly price at loss . This doesnot happen always, but it happend once.

zenbotbug

code4passion avatar Jan 09 '18 05:01 code4passion

screen shot 2018-01-08 at 9 09 10 pm

code4passion avatar Jan 09 '18 05:01 code4passion

This happens to me every day. I have to restart zenbot every 6 hours to avoid this bug.

srgkmv avatar Jan 09 '18 07:01 srgkmv

I think I found this as well but only after an update in the past few days.

How long have you been seeing this?

SlackerATX avatar Jan 09 '18 07:01 SlackerATX

This seems like a new bug in the past couple of days. I don't remember the sell price suck so off from the actual price.

2018-01-09 09:08:32 14654.37 BTC-USD +0.71% 576 -- 42 -0.1251 0.1108 +2.01% 0.00677 BTC 10132.01 USD -3.18% -0.57% manual limit SELL command executed

sell order completed at 2018-01-09 09:08:36:

0.00670523 BTC at 14289.91 USD total 95.8171 USD 0.0000% slippage (orig. price 14289.91 USD) execution: a few seconds

2018-01-09 09:13:42 14612.39 BTC-USD +0.42% 622 -- 41 -0.1566 0.1107 sold 0.00006 BTC 10227.83 USD -3.21% -0.31% manual limit BUY command executed 2018-01-09 09:13:42 14612.39 BTC-USD +0.42% 622 -- 41 -0.1566 0.1107 buying 0.00006 BTC 10227.83 USD -3.21% -0.31% buy order completed at 2018-01-09 09:13:53:

0.69294332 BTC at 14612.39 USD total 10125.55 USD 0.0000% slippage (orig. price 14612.39 USD) execution: a few seconds

2018-01-09 09:13:58 14612.40 BTC-USD +0.42% 623 -- 41 -0.1566 0.1107 bought 0.69301 BTC 102.27 USD -3.21% -0.31% manual limit SELL command executed

sell order completed at 2018-01-09 09:14:00:

0.68608093 BTC at 14289.91 USD total 9804.03 USD 0.0000% slippage (orig. price 14289.91 USD) execution: a few seconds

2018-01-09 09:14:24 14612.39 BTC-USD +0.42% 624 -- 41 -0.1566 0.1107 sold 0.00693 BTC 9906.31 USD -5.30% -2.46%

SlackerATX avatar Jan 09 '18 15:01 SlackerATX

I've experienced this bug as well. I think i first saw it after i pulled the changes on 1/3 or 1/4. I took some screenshots after i first noticed it.

price-bug2

Seems like the sell price got stuck. Notice the current price is 973.22, but it says it sold for 941. But i checked the exchange, and it did indeed sell for 973. Then a couple hours later, still stuck on the same price of 941, but now refusing to sell at a loss (profit) of +2.62%, when the current price is 990+.

price-bug

I started a new live test last night, and when i woke up, i found the bot trying to sell at 1135 when the current price was 1203. This time, it was not being blocked by config rules, but instead it gave a gdax api error each time it tried to sell. I did a manual sell and stopped the bot, then checked the exchange. The bot reports that it sold at 1135, for a total of 7.12, but the exchange shows it sold at 1203, for a total of 7.53. However, the next line of output shows the correct end balance of currency.

price-bug4

I think if i didn't do the manual sell, it would have probably sold at the price it was stuck at when the real price got back down to it. So as some others have said, the only remedy has been to stop and restart the bot to get it acting right again.

blevok avatar Jan 09 '18 16:01 blevok

Is everyone using trend_ema like I am? Or does this affect others than just trend?

SlackerATX avatar Jan 09 '18 17:01 SlackerATX

My first 2 screenshots were with trend_ema, and the third was with bollinger. I think i saw it with trendline and trust_distrust also, but i can't be 100% sure.

blevok avatar Jan 09 '18 17:01 blevok

Just commenting so you know I'm actively reading and looking into this issue in the little free time I have. I haven't seen it myself yet, could it have something to do with stop_loss hanging it up? Do you see it in sims too?

DeviaVir avatar Jan 09 '18 17:01 DeviaVir

FYI, I observed it in live and paper trading with the default max_sell_loss_pct of 25 and sell_stop_pct at the default of 0.

SlackerATX avatar Jan 09 '18 18:01 SlackerATX

@code4passion can you please try the changes i have pushed in #1098 and give feedback?

Shawn8901 avatar Jan 11 '18 14:01 Shawn8901

@Shawn8901 I think that did the trick. I just ran it in live trading on GDAX for 12 hours, and there were several disconnects, with buying and selling at the correct price afterwards.

blevok avatar Jan 11 '18 19:01 blevok

@DeviaVir @Shawn8901 Looks like i spoke too soon. This screenshot is the same session still running from my last post. As you can see, there was a disconnect, and then a new connection, and then 90 minutes later there was a buy. I checked the exchange, and the buy price and amount are accurate.

Then about 30 minutes later, i checked it and found my profit stop had been triggered, and it was trying to sell. I looked at the exchange, and there was no sell order. After the profit stop failed to sell or even submit an order, i tried a manual limit sell. That also did not cause it to submit an order. So then i did a manual market sell, and finally i saw an order pop up on the exchange. It sold at 1140.99, for a total of 7.48, but the bot reports that it sold at 1119.82, for a total of 7.36. And again, the next line of output in the console now shows the correct currency balance, despite the sell report output.

So since the issue occurred while the connection was stable, and after a good buy, maybe this is actually unrelated to the socket connection. It kind of looks like it could be related to the profit stop, since it was triggered in between the good buy and the price getting stuck. But that's just circumstantial evidence at the moment.

price-bug5

blevok avatar Jan 12 '18 01:01 blevok

It's not obvious to me why but this a commit that might be causing this.

https://github.com/DeviaVir/zenbot/commit/1f3f8eaf1f8b008c671ce0e0582363a359f08421#diff-a41b519e7979a713e894ef8d1b3fe568

SlackerATX avatar Jan 12 '18 02:01 SlackerATX

Just ran another test overnight, without the profit stop or any other configurable limit set to interfere. After running for 14 hours, with 5 successful limit buys/sells, and the only disconnect happening before any of the trades, the price got stuck again. I found it trying to sell for over an hour, so i checked the exchange, and there was no order. Again i tried a manual limit sell, and again, no order was sent to the exchange. But when i did a manual market sell, it did submit an order.

So when the price gets stuck, it becomes impossible to limit sell, and only market sell works, probably because it's getting the current price to sell at from the exchange at the time of the sell. So it seems that it's unrelated to any configuration options or the connection. Since there was no obvious event that could be related this time, i'm now at a loss to explain it. I've been skimming over trade.js and some other files, but so far nothing is jumping out at me.

blevok avatar Jan 12 '18 20:01 blevok

I've been running for a day after reverting the commit I mentioned above and I haven't seen the problem. Still keeping an eye out...

SlackerATX avatar Jan 13 '18 03:01 SlackerATX

Same as @SlackerATX Have not seen the issue after picking up latest commmit

code4passion avatar Jan 13 '18 07:01 code4passion

I tried pulling the latest changes, and reverted commit 1f3f8eaf1f8b008c671ce0e0582363a359f08421, but the issue still keeps happening.

I've been watching with the debug option, and when the issue happens, it starts printing this about three times a second, and just keeps doing that forever. Meanwhile i don't see any orders popping up on the exchange.

2018-01-14 00:11:14 - placing sell order... 2018-01-14 00:11:14 - post-only sell failed, re-ordering 2018-01-14 00:11:14 - sell order timed out, adjusting price

The thing that seems weird to me about this (other than the fact that it's not actually sending an order), is the post-only thing. I definitely have --post_only=false in the command. I'm starting a test now with post-only set to true.

blevok avatar Jan 14 '18 06:01 blevok

Well, no luck with that. I woke up to find it doing the same thing.

blevok avatar Jan 14 '18 20:01 blevok

@blevok Do u have the latest commit from unstable branch?

I have code up to following commit and i am not seeing the issue in paper mode

commit d1e38ec6c896ea698cec358ebccaf8513e16290b (HEAD -> unstable, origin/unstable) Author: Michael Sutton [email protected] Date: Thu Jan 11 12:00:47 2018 -0500

code4passion avatar Jan 14 '18 20:01 code4passion

@code4passion Yes, i checked and i do have that commit. But i'm pretty sure i've never seen this happen in paper mode, only in live trading with real orders. I haven't done much paper testing since i started live testing, but i did run one the night before last, which ran concurrently with a live test on another machine, and in the morning the paper instance was doing fine, while the live instance had gotten stuck.

blevok avatar Jan 14 '18 21:01 blevok