|
5 | 5 | import logging |
6 | 6 | from functools import partial |
7 | 7 |
|
8 | | -from cachetools import TTLCache, cached |
| 8 | +from cachetools import LRUCache, TTLCache, cached |
9 | 9 |
|
10 | 10 | from freqtrade.constants import Config, ListPairsWithTimeframes |
11 | 11 | from freqtrade.data.dataprovider import DataProvider |
@@ -56,6 +56,7 @@ def __init__(self, exchange, config: Config, dataprovider: DataProvider | None = |
56 | 56 | ) |
57 | 57 |
|
58 | 58 | self._check_backtest() |
| 59 | + self._not_expiring_cache: LRUCache = LRUCache(maxsize=1) |
59 | 60 |
|
60 | 61 | refresh_period = config.get("pairlist_refresh_period", 3600) |
61 | 62 | LoggingMixin.__init__(self, logger, refresh_period) |
@@ -109,7 +110,15 @@ def blacklist(self) -> list[str]: |
109 | 110 | @property |
110 | 111 | def expanded_blacklist(self) -> list[str]: |
111 | 112 | """The expanded blacklist (including wildcard expansion)""" |
112 | | - return expand_pairlist(self._blacklist, self._exchange.get_markets().keys()) |
| 113 | + eblacklist = self._not_expiring_cache.get("eblacklist") |
| 114 | + |
| 115 | + if not eblacklist: |
| 116 | + eblacklist = expand_pairlist(self._blacklist, self._exchange.get_markets().keys()) |
| 117 | + |
| 118 | + if self._config["runmode"] in (RunMode.BACKTEST, RunMode.HYPEROPT): |
| 119 | + self._not_expiring_cache["eblacklist"] = eblacklist.copy() |
| 120 | + |
| 121 | + return eblacklist |
113 | 122 |
|
114 | 123 | @property |
115 | 124 | def name_list(self) -> list[str]: |
@@ -157,16 +166,17 @@ def verify_blacklist(self, pairlist: list[str], logmethod) -> list[str]: |
157 | 166 | :param logmethod: Function that'll be called, `logger.info` or `logger.warning`. |
158 | 167 | :return: pairlist - blacklisted pairs |
159 | 168 | """ |
160 | | - try: |
161 | | - blacklist = self.expanded_blacklist |
162 | | - except ValueError as err: |
163 | | - logger.error(f"Pair blacklist contains an invalid Wildcard: {err}") |
164 | | - return [] |
165 | | - log_once = partial(self.log_once, logmethod=logmethod) |
166 | | - for pair in pairlist.copy(): |
167 | | - if pair in blacklist: |
168 | | - log_once(f"Pair {pair} in your blacklist. Removing it from whitelist...") |
169 | | - pairlist.remove(pair) |
| 169 | + if self._blacklist: |
| 170 | + try: |
| 171 | + blacklist = self.expanded_blacklist |
| 172 | + except ValueError as err: |
| 173 | + logger.error(f"Pair blacklist contains an invalid Wildcard: {err}") |
| 174 | + return [] |
| 175 | + log_once = partial(self.log_once, logmethod=logmethod) |
| 176 | + for pair in pairlist.copy(): |
| 177 | + if pair in blacklist: |
| 178 | + log_once(f"Pair {pair} in your blacklist. Removing it from whitelist...") |
| 179 | + pairlist.remove(pair) |
170 | 180 | return pairlist |
171 | 181 |
|
172 | 182 | def verify_whitelist( |
|
0 commit comments