Skip to content

Commit

Permalink
Expire cached pairs in age-filter once per day
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Sep 14, 2021
1 parent 8afb3c4 commit c9ba52d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions freqtrade/plugins/pairlist/AgeFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from freqtrade.exceptions import OperationalException
from freqtrade.misc import plural
from freqtrade.plugins.pairlist.IPairList import IPairList
from freqtrade.configuration import PeriodicCache


logger = logging.getLogger(__name__)
Expand All @@ -25,6 +26,7 @@ def __init__(self, exchange, pairlistmanager,

# Checked symbols cache (dictionary of ticker symbol => timestamp)
self._symbolsChecked: Dict[str, int] = {}
self._too_young_pairs = PeriodicCache(maxsize=1000, ttl=86_400)

self._min_days_listed = pairlistconfig.get('min_days_listed', 10)
self._max_days_listed = pairlistconfig.get('max_days_listed', None)
Expand Down Expand Up @@ -69,10 +71,12 @@ def filter_pairlist(self, pairlist: List[str], tickers: Dict) -> List[str]:
:param tickers: Tickers (from exchange.get_tickers()). May be cached.
:return: new allowlist
"""
needed_pairs = [(p, '1d') for p in pairlist if p not in self._symbolsChecked]
needed_pairs = [
(p, '1d') for p in pairlist
if p not in self._symbolsChecked and p not in self._too_young_pairs]
if not needed_pairs:
return pairlist

logger.info(f"needed pairs {needed_pairs}")
since_days = -(
self._max_days_listed if self._max_days_listed else self._min_days_listed
) - 1
Expand Down Expand Up @@ -118,5 +122,6 @@ def _validate_pair_loc(self, pair: str, daily_candles: Optional[DataFrame]) -> b
" or more than "
f"{self._max_days_listed} {plural(self._max_days_listed, 'day')}"
) if self._max_days_listed else ''), logger.info)
self._too_young_pairs[pair] = arrow.utcnow().int_timestamp * 1000
return False
return False

0 comments on commit c9ba52d

Please sign in to comment.