refactor: make klines_last_request private
This commit is contained in:
@@ -29,7 +29,7 @@ class ExchangeWS:
|
||||
self._klines_watching: set[PairWithTimeframe] = set()
|
||||
self._klines_scheduled: set[PairWithTimeframe] = set()
|
||||
self.klines_last_refresh: dict[PairWithTimeframe, float] = {}
|
||||
self.klines_last_request: dict[PairWithTimeframe, float] = {}
|
||||
self._klines_last_request: dict[PairWithTimeframe, float] = {}
|
||||
self._thread = Thread(name="ccxt_ws", target=self._start_forever)
|
||||
self._thread.start()
|
||||
|
||||
@@ -130,7 +130,7 @@ class ExchangeWS:
|
||||
for p in list(self._klines_watching):
|
||||
_, timeframe, _ = p
|
||||
timeframe_s = timeframe_to_seconds(timeframe)
|
||||
last_refresh = self.klines_last_request.get(p, 0)
|
||||
last_refresh = self._klines_last_request.get(p, 0)
|
||||
if last_refresh > 0 and (dt_ts() - last_refresh) > ((timeframe_s + 20) * 1000):
|
||||
logger.info(f"Removing {p} from websocket watchlist.")
|
||||
self._klines_watching.discard(p)
|
||||
@@ -238,7 +238,7 @@ class ExchangeWS:
|
||||
return
|
||||
with self._state_lock:
|
||||
self._klines_watching.add((pair, timeframe, candle_type))
|
||||
self.klines_last_request[(pair, timeframe, candle_type)] = dt_ts()
|
||||
self._klines_last_request[(pair, timeframe, candle_type)] = dt_ts()
|
||||
# asyncio.run_coroutine_threadsafe(self.schedule_schedule(), loop=self._loop)
|
||||
asyncio.run_coroutine_threadsafe(self._schedule_while_true(), loop=self._loop)
|
||||
self.cleanup_expired()
|
||||
|
||||
@@ -27,7 +27,7 @@ def test_exchangews_init(mocker):
|
||||
assert exchange_ws._klines_watching == set()
|
||||
assert exchange_ws._klines_scheduled == set()
|
||||
assert exchange_ws.klines_last_refresh == {}
|
||||
assert exchange_ws.klines_last_request == {}
|
||||
assert exchange_ws._klines_last_request == {}
|
||||
# Cleanup
|
||||
exchange_ws.cleanup()
|
||||
|
||||
@@ -120,7 +120,7 @@ def test_exchangews_schedule_ohlcv_loop_not_ready(mocker, caplog):
|
||||
exchange_ws.schedule_ohlcv("ETH/BTC", "1m", CandleType.SPOT)
|
||||
|
||||
assert exchange_ws._klines_watching == set()
|
||||
assert exchange_ws.klines_last_request == {}
|
||||
assert exchange_ws._klines_last_request == {}
|
||||
assert run_threadsafe.call_count == 0
|
||||
assert log_has_re("Websocket loop not ready. Could not schedule ETH/BTC, 1m", caplog)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user