mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-03-01 07:42:40 +00:00
Add cache for gen_pairlist() in StaticPairList in backtest mode
This commit is contained in:
@@ -7,6 +7,9 @@ Provides pair white list as it configured in config
|
||||
import logging
|
||||
from copy import deepcopy
|
||||
|
||||
from cachetools import LRUCache
|
||||
|
||||
from freqtrade.enums.runmode import RunMode
|
||||
from freqtrade.exchange.exchange_types import Tickers
|
||||
from freqtrade.plugins.pairlist.IPairList import IPairList, PairlistParameter, SupportsBacktesting
|
||||
|
||||
@@ -22,6 +25,7 @@ class StaticPairList(IPairList):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self._allow_inactive = self._pairlistconfig.get("allow_inactive", False)
|
||||
self._pair_cache: LRUCache = LRUCache(maxsize=1)
|
||||
|
||||
@property
|
||||
def needstickers(self) -> bool:
|
||||
@@ -60,15 +64,23 @@ class StaticPairList(IPairList):
|
||||
:param tickers: Tickers (from exchange.get_tickers). May be cached.
|
||||
:return: List of pairs
|
||||
"""
|
||||
wl = self.verify_whitelist(
|
||||
self._config["exchange"]["pair_whitelist"], logger.info, keep_invalid=True
|
||||
)
|
||||
if self._allow_inactive:
|
||||
return wl
|
||||
else:
|
||||
# Avoid implicit filtering of "verify_whitelist" to keep
|
||||
# proper warnings in the log
|
||||
return self._whitelist_for_active_markets(wl)
|
||||
pairlist = self._pair_cache.get("pairlist")
|
||||
|
||||
if not pairlist:
|
||||
wl = self.verify_whitelist(
|
||||
self._config["exchange"]["pair_whitelist"], logger.info, keep_invalid=True
|
||||
)
|
||||
if self._allow_inactive:
|
||||
pairlist = wl
|
||||
else:
|
||||
# Avoid implicit filtering of "verify_whitelist" to keep
|
||||
# proper warnings in the log
|
||||
pairlist = self._whitelist_for_active_markets(wl)
|
||||
|
||||
if self._config["runmode"] in (RunMode.BACKTEST, RunMode.HYPEROPT):
|
||||
self._pair_cache["pairlist"] = pairlist.copy()
|
||||
|
||||
return pairlist
|
||||
|
||||
def filter_pairlist(self, pairlist: list[str], tickers: Tickers) -> list[str]:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user