Refactor ohlcv caching to exchange class

This commit is contained in:
Matthias
2024-02-17 16:17:32 +01:00
parent 8033faa2f2
commit bcfe7ef547
2 changed files with 38 additions and 14 deletions

View File

@@ -14,7 +14,7 @@ from freqtrade.exceptions import OperationalException
from freqtrade.exchange import timeframe_to_minutes, timeframe_to_prev_date
from freqtrade.exchange.types import Tickers
from freqtrade.plugins.pairlist.IPairList import IPairList, PairlistParameter
from freqtrade.util import PeriodicCache, dt_now, format_ms_time
from freqtrade.util import dt_now, format_ms_time
logger = logging.getLogger(__name__)
@@ -63,7 +63,6 @@ class VolumePairList(IPairList):
# get timeframe in minutes and seconds
self._tf_in_min = timeframe_to_minutes(self._lookback_timeframe)
_tf_in_sec = self._tf_in_min * 60
self._candle_cache = PeriodicCache(maxsize=1000, ttl=_tf_in_sec)
# wether to use range lookback or not
self._use_range = (self._tf_in_min > 0) & (self._lookback_period > 0)
@@ -230,18 +229,7 @@ class VolumePairList(IPairList):
if p not in self._pair_cache
]
# Get all candles
candles = {
c: self._candle_cache.get(c, None) for c in needed_pairs
if c in self._candle_cache
}
pairs_to_download = [p for p in needed_pairs if p not in candles]
if pairs_to_download:
candles = self._exchange.refresh_latest_ohlcv(
pairs_to_download, since_ms=since_ms, cache=False
)
for c, val in candles.items():
self._candle_cache[c] = val
candles = self._exchange.refresh_ohlcv_with_cache(needed_pairs, since_ms)
for i, p in enumerate(filtered_tickers):
contract_size = self._exchange.markets[p['symbol']].get('contractSize', 1.0) or 1.0