From e00b74c0e0491fb3cf5147f44b60d87970acc492 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 25 May 2025 19:39:38 +0200 Subject: [PATCH] fix: capture ws edge-case on reconnect --- freqtrade/exchange/exchange.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 88e392fc8..94e998429 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -2449,7 +2449,15 @@ class Exchange: self._exchange_ws.klines_last_refresh.get((pair, timeframe, candle_type), 0) ) - if candles and candles[-1][0] >= prev_candle_ts and last_refresh_time >= half_candle: + if ( + candles + and ( + (len(candles) > 1 and candles[-1][0] >= prev_candle_ts) + # Edgecase on reconnect, where 1 candle is available but it's the current one + or (len(candles) == 1 and candles[-1][0] < candle_ts) + ) + and last_refresh_time >= half_candle + ): # Usable result, candle contains the previous candle. # Also, we check if the last refresh time is no more than half the candle ago. logger.debug(f"reuse watch result for {pair}, {timeframe}, {last_refresh_time}")