From 9be29c6e9248364a6c6d2fd72202b88512cef8cc Mon Sep 17 00:00:00 2001 From: Reigo Reinmets Date: Mon, 13 Dec 2021 20:44:18 +0200 Subject: [PATCH] Theoretically fix second order timeout/canceling deleting the whole order. --- freqtrade/freqtradebot.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index c6a2d667f..4cd8b51a4 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -1034,10 +1034,16 @@ class FreqtradeBot(LoggingMixin): filled_amount = safe_value_fallback2(corder, order, 'filled', 'filled') if isclose(filled_amount, 0.0, abs_tol=constants.MATH_CLOSE_PREC): logger.info('Buy order fully cancelled. Removing %s from database.', trade) - # if trade is not partially completed, just delete the trade - trade.delete() - was_trade_fully_canceled = True - reason += f", {constants.CANCEL_REASON['FULLY_CANCELLED']}" + # if trade is not partially completed and it's the only order, just delete the trade + if len(trade.orders) <= 1: + trade.delete() + was_trade_fully_canceled = True + reason += f", {constants.CANCEL_REASON['FULLY_CANCELLED']}" + else: + # FIXME TODO: This could possibly reworked to not duplicate the code 15 lines below. + self.update_trade_state(trade, trade.open_order_id, corder) + trade.open_order_id = None + logger.info('Partial buy order timeout for %s.', trade) else: # if trade is partially complete, edit the stake details for the trade # and close the order