@@ -120,6 +120,17 @@ def ohlcvs(self, pair: str, timeframe: str) -> list[list]:
120120 # TemporaryError does not cause backoff - so we're essentially retrying immediately
121121 raise TemporaryError (f"Error deepcopying: { e } " ) from e
122122
123+ def get_ohlcv_with_refresh (
124+ self , pair : str , timeframe : str , candle_type : CandleType
125+ ) -> tuple [list [list ], float ]:
126+ """
127+ Get deepcopied klines and update the last refresh time
128+ """
129+ ohlcvs = self .ohlcvs (pair , timeframe )
130+ with self ._state_lock :
131+ last_refresh = self .klines_last_refresh .get ((pair , timeframe , candle_type ), 0 )
132+ return ohlcvs , last_refresh
133+
123134 def cleanup_expired (self ) -> None :
124135 """
125136 Remove pairs from watchlist if they've not been requested within
@@ -254,10 +265,7 @@ async def get_ohlcv(
254265 Returns cached klines from ccxt's "watch" cache.
255266 :param candle_ts: timestamp of the end-time of the candle we expect.
256267 """
257- # Deepcopy the response - as it might be modified in the background as new messages arrive
258- candles = self .ohlcvs (pair , timeframe )
259- with self ._state_lock :
260- refresh_date = self .klines_last_refresh .get ((pair , timeframe , candle_type ), 0 )
268+ candles , refresh_date = self .get_ohlcv_with_refresh (pair , timeframe , candle_type )
261269 received_ts = candles [- 1 ][0 ] if candles else 0
262270 drop_hint = received_ts >= candle_ts
263271 if refresh_date and received_ts > refresh_date :
0 commit comments