mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-16 12:51:14 +00:00
Improve ohlcv pair cache with since_ms
avoids some rare bugs in more complex configurations.
This commit is contained in:
@@ -2314,16 +2314,16 @@ class Exchange:
|
|||||||
|
|
||||||
timeframes = {p[1] for p in pairs}
|
timeframes = {p[1] for p in pairs}
|
||||||
for timeframe in timeframes:
|
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)
|
timeframe_in_sec = timeframe_to_seconds(timeframe)
|
||||||
# Initialise cache
|
# Initialise cache
|
||||||
self._expiring_candle_cache[timeframe] = PeriodicCache(ttl=timeframe_in_sec,
|
self._expiring_candle_cache[(timeframe, since_ms)] = PeriodicCache(
|
||||||
maxsize=1000)
|
ttl=timeframe_in_sec, maxsize=1000)
|
||||||
|
|
||||||
# Get candles from cache
|
# Get candles from cache
|
||||||
candles = {
|
candles = {
|
||||||
c: self._expiring_candle_cache[c[1]].get(c, None) for c in pairs
|
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]]
|
if c in self._expiring_candle_cache[(c[1], since_ms)]
|
||||||
}
|
}
|
||||||
pairs_to_download = [p for p in pairs if p not in candles]
|
pairs_to_download = [p for p in pairs if p not in candles]
|
||||||
if pairs_to_download:
|
if pairs_to_download:
|
||||||
@@ -2331,7 +2331,7 @@ class Exchange:
|
|||||||
pairs_to_download, since_ms=since_ms, cache=False
|
pairs_to_download, since_ms=since_ms, cache=False
|
||||||
)
|
)
|
||||||
for c, val in candles.items():
|
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
|
return candles
|
||||||
|
|
||||||
def _now_is_time_to_refresh(self, pair: str, timeframe: str, candle_type: CandleType) -> bool:
|
def _now_is_time_to_refresh(self, pair: str, timeframe: str, candle_type: CandleType) -> bool:
|
||||||
|
|||||||
Reference in New Issue
Block a user