edeng23 / binance-trade-bot

Automated cryptocurrency trading bot
GNU General Public License v3.0
7.9k stars 2.19k forks source link

If buy order is not fulfilled within time period and is cancelled, it goes back to wrong coin #294

Open iangorse opened 3 years ago

iangorse commented 3 years ago

If the bot cancels a buy order due to the timeout, the "current" coin is the bridge coin, however bot think it's the previous coin. This does fix itself on next jump but would make more sense if it purchased a random coin/initial coin instead?

I have changed the wording on my logging but this highlights the issue.

2021-04-22 11:28:47,638 - crypto_trading_logger - INFO - Will be jumping from <ENJ> to QTUM> > 
2021-04-22 11:28:50,195 - crypto_trading_logger - INFO - Selling 117.8 of ENJ                  
2021-04-22 11:28:53,594 - crypto_trading_logger - INFO - Selling 117.8 of ENJ -> Sold          
2021-04-22 11:28:57,079 - crypto_trading_logger - INFO - Created Buy Order for 19.479 of QTUM  
2021-04-22 11:28:57,705 - crypto_trading_logger - INFO - APIError(code=-2013): Order does not exist.  
2021-04-22 11:33:58,444 - crypto_trading_logger - INFO - Order timeout, canceled...                   
2021-04-22 11:33:58,446 - crypto_trading_logger - INFO - Going back to scouting mode...               
2021-04-22 11:33:58,458 - crypto_trading_logger - INFO - Couldn't buy, going back to scouting mode... 
2021-04-22 11:34:09.272396 - CONSOLE - INFO - I am scouting the best trades. Current coin: ENJUSDT

Timeline of events 11:28:53 - Bot sold ENJ 11:28:57 - Bot created a limit order for QTUM 11:33:58 - Binance did not fulfill the order in time so the bot cancelled the order

My binance account now has the Bridge coin and zero ENJ

11:33:58 - Bot goes back to scouting 11:34:09 - Bot is scouting using previous coin ENJ but I no longer have any

I would expect this to purchase a random coin with bridge, as per very first run with no database

erenatas commented 3 years ago

Had this exact problem twice so far. Sell timeout is handled properly though.

j-waters commented 3 years ago

This is done by the bridge_scout method https://github.com/edeng23/binance-trade-bot/blob/master/binance_trade_bot/auto_trader.py#L151, however it currently isn't being called by the default strategy since it can be a little slow. Try switching to the multiple coins strategy if you'd like this functionality, or create a custom strategy that inherits the default one

iangorse commented 3 years ago

Oh I think I see. I noticed the call to bridge_scout() was removed in default_strategy for PR #195 If by invoking bridge_scout() again, this will check to see if it has enough coin. As it wont have, this would then run the full slow every coin to every coin scout. This takes an hour on my list.

Will give this a go later to see what it is like.

j-waters commented 3 years ago

Yeah ideally it would only be called if we only have bridge coin available or just failed a trade. If you come up with a good solution feel free to make a PR!

Blaklis commented 3 years ago

In fact, it does that to simulate it's still on the last previous coin, to keep scouting with the ratio from the previous coin. It will then detect that you don't have the coin when jumping. Still a tricky - not clean way imho.

idkravitz commented 3 years ago

Yeah ideally it would only be called if we only have bridge coin available or just failed a trade. If you come up with a good solution feel free to make a PR!

Or we can cache failed result (in case of min_notional filter) for bridge_scout and invalidate it on bridge amount change

Amraki commented 3 years ago

I just ran into this problem on your latest version, @idkravitz. The bot never bought the HNT so it was stuck with USDT but still scouting as if it had the previous coin, QTUM. After about 30 minutes, it managed to buy PAXG. Had a good ratio between QTUM and PAXG not been found, it could have been stuck longer. And of course, I no longer had QTUM by then so the jump may not have been the most ideal.

Any help would be appreciated. And I'll be glad to help clear out some of the old problems as best as I can. My python is limited so I don't feel comfortable contributing PR's yet.

2021-05-20 06:04:28,757 - crypto_trading_logger - INFO - BUY QTY 1.7 of <HNT>
2021-05-20 06:04:28,811 - crypto_trading_logger - INFO - {'symbol': 'HNTUSDT', 'orderId': 8910897, 'orderListId': -1, 'clientOrderId': 'WX6QKPD4J4xv71EOkDUvcp', 'transactTime': 1621505068646, 'price': '11.80508000', 'origQty': '1.70000000', 'executedQty': '0.00000000', 'cummulativeQuoteQty': '0.00000000', 'status': 'NEW', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'BUY', 'fills': []}
2021-05-20 06:14:29,375 - crypto_trading_logger - INFO - Order timeout, canceled...
2021-05-20 06:14:29,375 - crypto_trading_logger - INFO - Going back to scouting mode...
2021-05-20 06:14:29,376 - crypto_trading_logger - INFO - Couldn't buy, going back to scouting mode...
2021-05-20 06:46:39,520 - crypto_trading_logger - INFO - Will be jumping from <QTUM> to PAXGTUMUSDT
2021-05-20 06:46:39,521 - crypto_trading_logger - INFO - Skipping sell
2021-05-20 06:46:43,022 - crypto_trading_logger - INFO - BUY QTY 0.01133 of <PAXG>
2021-05-20 06:46:43,082 - crypto_trading_logger - INFO - {'symbol': 'PAXGUSDT', 'orderId': 758883, 'orderListId': -1, 'clientOrderId': 'd5xCmybbQqqduYXFK6BN5r', 'transactTime': 1621507602898, 'price': '1871.18000000', 'origQty': '0.01133000', 'executedQty': '0.00000000', 'cummulativeQuoteQty': '0.00000000', 'status': 'NEW', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'BUY', 'fills': []}
2021-05-20 06:52:10,068 - crypto_trading_logger - INFO - Bought PAXG
2021-05-20 06:56:40.356124 - CONSOLE - INFO - I am scouting the best trades. Current coin: PAXGUSDT
tntwist commented 3 years ago

Hi, I just made pr which should fix this issue. Would be glad if someone could review this. 😄