diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index f69380727..eec631b68 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -2397,7 +2397,7 @@ class Exchange: if self._exchange_ws: candle_ts = dt_ts(timeframe_to_prev_date(timeframe)) prev_candle_ts = dt_ts(date_minus_candles(timeframe, 1)) - candles = self._exchange_ws.ohlcvs.get(pair, {}).get(timeframe) + candles = self._exchange_ws.ohlcvs(pair, timeframe) half_candle = int(candle_ts - (candle_ts - prev_candle_ts) * 0.5) last_refresh_time = int( self._exchange_ws.klines_last_refresh.get((pair, timeframe, candle_type), 0) diff --git a/freqtrade/exchange/exchange_ws.py b/freqtrade/exchange/exchange_ws.py index b907a919e..0181267c6 100644 --- a/freqtrade/exchange/exchange_ws.py +++ b/freqtrade/exchange/exchange_ws.py @@ -83,12 +83,13 @@ class ExchangeWS: """ self._ccxt_object.ohlcvs.get(paircomb[0], {}).pop(paircomb[1], None) - @property - def ohlcvs(self) -> dict[str, dict[str, list[list]]]: + def ohlcvs(self, pair: str, timeframe: str) -> list[list]: """ - Returns the ccxt cache for OHLCV data + Returns a copy of the klines for a pair/timeframe combination + Note: this will only contain the data received from the websocket + so the data will build up over time. """ - return self._ccxt_object.ohlcvs + return deepcopy(self._ccxt_object.ohlcvs.get(pair, {}).get(timeframe, [])) def cleanup_expired(self) -> None: """ @@ -185,7 +186,7 @@ class ExchangeWS: :param candle_ts: timestamp of the end-time of the candle we expect. """ # Deepcopy the response - as it might be modified in the background as new messages arrive - candles = deepcopy(self._ccxt_object.ohlcvs.get(pair, {}).get(timeframe)) + candles = self.ohlcvs(pair, timeframe) refresh_date = self.klines_last_refresh[(pair, timeframe, candle_type)] received_ts = candles[-1][0] if candles else 0 drop_hint = received_ts >= candle_ts