feat(agefilter): add max_days_listed

This commit is contained in:
kevinjulian
2021-07-03 23:58:04 +07:00
parent 9d6860337f
commit 3d9f3eeb07
4 changed files with 47 additions and 13 deletions

View File

@@ -27,6 +27,7 @@ class AgeFilter(IPairList):
super().__init__(exchange, pairlistmanager, config, pairlistconfig, pairlist_pos)
self._min_days_listed = pairlistconfig.get('min_days_listed', 10)
self._max_days_listed = pairlistconfig.get('max_days_listed', None)
if self._min_days_listed < 1:
raise OperationalException("AgeFilter requires min_days_listed to be >= 1")
@@ -34,6 +35,8 @@ class AgeFilter(IPairList):
raise OperationalException("AgeFilter requires min_days_listed to not exceed "
"exchange max request size "
f"({exchange.ohlcv_candle_limit('1d')})")
if self._max_days_listed and self._max_days_listed <= self._min_days_listed:
raise OperationalException("AgeFilter max_days_listed <= min_days_listed not permitted")
@property
def needstickers(self) -> bool:
@@ -49,7 +52,9 @@ class AgeFilter(IPairList):
Short whitelist method description - used for startup-messages
"""
return (f"{self.name} - Filtering pairs with age less than "
f"{self._min_days_listed} {plural(self._min_days_listed, 'day')}.")
f"{self._min_days_listed} {plural(self._min_days_listed, 'day')}"
" or more than "
f"{self._max_days_listed} {plural(self._max_days_listed, 'day')}")
def filter_pairlist(self, pairlist: List[str], tickers: Dict) -> List[str]:
"""
@@ -61,9 +66,10 @@ class AgeFilter(IPairList):
if not needed_pairs:
return pairlist
since_days = -(self._max_days_listed if self._max_days_listed else self._min_days_listed) - 1
since_ms = int(arrow.utcnow()
.floor('day')
.shift(days=-self._min_days_listed - 1)
.shift(days=since_days)
.float_timestamp) * 1000
candles = self._exchange.refresh_latest_ohlcv(needed_pairs, since_ms=since_ms, cache=False)
if self._enabled:
@@ -86,7 +92,8 @@ class AgeFilter(IPairList):
return True
if daily_candles is not None:
if len(daily_candles) >= self._min_days_listed:
if len(daily_candles) >= self._min_days_listed and \
len(daily_candles) <= self._max_days_listed:
# We have fetched at least the minimum required number of daily candles
# Add to cache, store the time we last checked this symbol
self._symbolsChecked[pair] = int(arrow.utcnow().float_timestamp) * 1000
@@ -94,6 +101,8 @@ class AgeFilter(IPairList):
else:
self.log_once(f"Removed {pair} from whitelist, because age "
f"{len(daily_candles)} is less than {self._min_days_listed} "
f"{plural(self._min_days_listed, 'day')}", logger.info)
f"{plural(self._min_days_listed, 'day')} or more than "
f"{self._max_days_listed} {plural(self._max_days_listed, 'day')}",
logger.info)
return False
return False