Improve ohlcv pair cache with since_ms

avoids some rare bugs in more complex configurations.
This commit is contained in:
Matthias 2024-02-22 06:38:28 +01:00
parent 3680e199ce
commit 4cfd5d004e

View File

@ -2171,16 +2171,16 @@ class Exchange:
timeframes = {p[1] for p in pairs}
for timeframe in timeframes:
if timeframe not in self._expiring_candle_cache:
if (timeframe, since_ms) not in self._expiring_candle_cache:
timeframe_in_sec = timeframe_to_seconds(timeframe)
# Initialise cache
self._expiring_candle_cache[timeframe] = PeriodicCache(ttl=timeframe_in_sec,
maxsize=1000)
self._expiring_candle_cache[(timeframe, since_ms)] = PeriodicCache(
ttl=timeframe_in_sec, maxsize=1000)
# Get candles from cache
candles = {
c: self._expiring_candle_cache[c[1]].get(c, None) for c in pairs
if c in self._expiring_candle_cache[c[1]]
c: self._expiring_candle_cache[(c[1], since_ms)].get(c, None) for c in pairs
if c in self._expiring_candle_cache[(c[1], since_ms)]
}
pairs_to_download = [p for p in pairs if p not in candles]
if pairs_to_download:
@ -2188,7 +2188,7 @@ class Exchange:
pairs_to_download, since_ms=since_ms, cache=False
)
for c, val in candles.items():
self._expiring_candle_cache[c[1]][c] = val
self._expiring_candle_cache[(c[1], since_ms)][c] = val
return candles
def _now_is_time_to_refresh(self, pair: str, timeframe: str, candle_type: CandleType) -> bool: