From ca22d857b7369c868214ffea456b322b159e7da2 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 3 Oct 2022 18:09:53 +0200 Subject: [PATCH] Improve handling of trades that fail to cancel as they are closed --- freqtrade/freqtradebot.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 2b20e40fd..4ec9c34ce 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -1444,9 +1444,14 @@ class FreqtradeBot(LoggingMixin): trade.close_profit = None trade.close_profit_abs = None # Set exit_reason for fill message + exit_reason_prev = trade.exit_reason trade.exit_reason = trade.exit_reason + f", {reason}" if trade.exit_reason else reason self.update_trade_state(trade, trade.open_order_id, co) - trade.exit_reason = None + # Order might be filled above in odd timing issues. + if co.get('status') in ('canceled', 'cancelled'): + trade.exit_reason = None + else: + trade.exit_reason = exit_reason_prev logger.info(f'{trade.exit_side.capitalize()} order {reason} for {trade}.') cancelled = True