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
|
import logging
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
|
from cachetools import LRUCache
|
||||||
|
|
||||||
|
from freqtrade.enums.runmode import RunMode
|
||||||
from freqtrade.exchange.exchange_types import Tickers
|
from freqtrade.exchange.exchange_types import Tickers
|
||||||
from freqtrade.plugins.pairlist.IPairList import IPairList, PairlistParameter, SupportsBacktesting
|
from freqtrade.plugins.pairlist.IPairList import IPairList, PairlistParameter, SupportsBacktesting
|
||||||
|
|
||||||
@@ -22,6 +25,7 @@ class StaticPairList(IPairList):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
self._allow_inactive = self._pairlistconfig.get("allow_inactive", False)
|
self._allow_inactive = self._pairlistconfig.get("allow_inactive", False)
|
||||||
|
self._pair_cache: LRUCache = LRUCache(maxsize=1)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def needstickers(self) -> bool:
|
def needstickers(self) -> bool:
|
||||||
@@ -60,15 +64,23 @@ class StaticPairList(IPairList):
|
|||||||
:param tickers: Tickers (from exchange.get_tickers). May be cached.
|
:param tickers: Tickers (from exchange.get_tickers). May be cached.
|
||||||
:return: List of pairs
|
:return: List of pairs
|
||||||
"""
|
"""
|
||||||
wl = self.verify_whitelist(
|
pairlist = self._pair_cache.get("pairlist")
|
||||||
self._config["exchange"]["pair_whitelist"], logger.info, keep_invalid=True
|
|
||||||
)
|
if not pairlist:
|
||||||
if self._allow_inactive:
|
wl = self.verify_whitelist(
|
||||||
return wl
|
self._config["exchange"]["pair_whitelist"], logger.info, keep_invalid=True
|
||||||
else:
|
)
|
||||||
# Avoid implicit filtering of "verify_whitelist" to keep
|
if self._allow_inactive:
|
||||||
# proper warnings in the log
|
pairlist = wl
|
||||||
return self._whitelist_for_active_markets(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]:
|
def filter_pairlist(self, pairlist: list[str], tickers: Tickers) -> list[str]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user