Evict cache if we didn't get new candles for X hours
This commit is contained in:
parent
f475c6c305
commit
92a1d58df8
@ -1854,7 +1854,11 @@ class Exchange:
|
||||
since_ms: Optional[int], cache: bool) -> Coroutine:
|
||||
not_all_data = self.required_candle_call_count > 1
|
||||
if cache and (pair, timeframe, candle_type) in self._klines:
|
||||
# Not in cache - force multi-calls
|
||||
candle_limit = self.ohlcv_candle_limit(timeframe, candle_type)
|
||||
min_date = date_minus_candles(timeframe, candle_limit - 5).timestamp()
|
||||
# Check if 1 call can get us updated candles without hole in the data.
|
||||
if min_date < self._pairs_last_refresh_time.get((pair, timeframe, candle_type), 0):
|
||||
# Cache can be used - do one-off call.
|
||||
not_all_data = False
|
||||
|
||||
if (not since_ms
|
||||
|
@ -2145,13 +2145,13 @@ def test_refresh_latest_ohlcv(mocker, default_conf, caplog, candle_type) -> None
|
||||
f"{pairs[0][1]}, {candle_type} ...",
|
||||
caplog)
|
||||
caplog.clear()
|
||||
# Reset refresh times - must do 1 call per pair (even though required_calls is 2)
|
||||
# Reset refresh times - must do 2 call per pair as cache is expired
|
||||
exchange._pairs_last_refresh_time = {}
|
||||
res = exchange.refresh_latest_ohlcv(
|
||||
[('IOTA/ETH', '5m', candle_type), ('XRP/ETH', '5m', candle_type)])
|
||||
assert len(res) == len(pairs)
|
||||
|
||||
assert exchange._api_async.fetch_ohlcv.call_count == 2
|
||||
assert exchange._api_async.fetch_ohlcv.call_count == 4
|
||||
|
||||
# cache - but disabled caching
|
||||
exchange._api_async.fetch_ohlcv.reset_mock()
|
||||
|
Loading…
Reference in New Issue
Block a user