mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Refactor verify_blacklist()
This commit is contained in:
parent
d438af342c
commit
e96e28df07
|
@ -3,7 +3,6 @@ PairList Handler base class
|
|||
"""
|
||||
import logging
|
||||
from abc import ABC, abstractmethod, abstractproperty
|
||||
from copy import deepcopy
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from cachetools import TTLCache, cached
|
||||
|
@ -87,38 +86,14 @@ class IPairList(ABC):
|
|||
:return: new whitelist
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def verify_blacklist(pairlist: List[str], blacklist: List[str],
|
||||
aswarning: bool) -> List[str]:
|
||||
"""
|
||||
Verify and remove items from pairlist - returning a filtered pairlist.
|
||||
Logs a warning or info depending on `aswarning`.
|
||||
Pairlist Handlers explicitly using this method shall use `aswarning=False`!
|
||||
:param pairlist: Pairlist to validate
|
||||
:param blacklist: Blacklist to validate pairlist against
|
||||
:param aswarning: Log message as Warning or Info
|
||||
:return: pairlist - blacklisted pairs
|
||||
"""
|
||||
for pair in deepcopy(pairlist):
|
||||
if pair in blacklist:
|
||||
if aswarning:
|
||||
logger.warning(f"Pair {pair} in your blacklist. Removing it from whitelist...")
|
||||
else:
|
||||
logger.info(f"Pair {pair} in your blacklist. Removing it from whitelist...")
|
||||
pairlist.remove(pair)
|
||||
return pairlist
|
||||
|
||||
def _verify_blacklist(self, pairlist: List[str], aswarning: bool = True) -> List[str]:
|
||||
def verify_blacklist(self, pairlist: List[str]) -> List[str]:
|
||||
"""
|
||||
Proxy method to verify_blacklist for easy access for child classes.
|
||||
Logs a warning or info depending on `aswarning`.
|
||||
Pairlists explicitly using this method shall use aswarning=False!
|
||||
Uses `aswarning=False`, as it should be for Pairlist Handlers.
|
||||
:param pairlist: Pairlist to validate
|
||||
:param aswarning: Log message as Warning or info.
|
||||
:return: pairlist - blacklisted pairs
|
||||
"""
|
||||
return IPairList.verify_blacklist(pairlist, self._pairlistmanager.blacklist,
|
||||
aswarning=aswarning)
|
||||
return self._pairlistmanager.verify_blacklist(pairlist, aswarning=False)
|
||||
|
||||
def _whitelist_for_active_markets(self, pairlist: List[str]) -> List[str]:
|
||||
"""
|
||||
|
|
|
@ -115,7 +115,7 @@ class VolumePairList(IPairList):
|
|||
|
||||
# Validate whitelist to only have active market pairs
|
||||
pairs = self._whitelist_for_active_markets([s['symbol'] for s in sorted_tickers])
|
||||
pairs = self._verify_blacklist(pairs, aswarning=False)
|
||||
pairs = self.verify_blacklist(pairs)
|
||||
# Limit pairlist to the requested number of pairs
|
||||
pairs = pairs[:self._number_pairs]
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ class PairListManager():
|
|||
|
||||
# Validation against blacklist happens after the chain of Pairlist Handlers
|
||||
# to ensure blacklist is respected.
|
||||
pairlist = IPairList.verify_blacklist(pairlist, self.blacklist, True)
|
||||
pairlist = self.verify_blacklist(pairlist, True)
|
||||
|
||||
self._whitelist = pairlist
|
||||
|
||||
|
@ -110,6 +110,24 @@ class PairListManager():
|
|||
|
||||
return pairlist
|
||||
|
||||
def verify_blacklist(self, pairlist: List[str], aswarning: bool) -> List[str]:
|
||||
"""
|
||||
Verify and remove items from pairlist - returning a filtered pairlist.
|
||||
Logs a warning or info depending on `aswarning`.
|
||||
Pairlist Handlers explicitly using this method shall use `aswarning=False`!
|
||||
:param pairlist: Pairlist to validate
|
||||
:param aswarning: Log message as Warning or Info
|
||||
:return: pairlist - blacklisted pairs
|
||||
"""
|
||||
for pair in deepcopy(pairlist):
|
||||
if pair in self._blacklist:
|
||||
if aswarning:
|
||||
logger.warning(f"Pair {pair} in your blacklist. Removing it from whitelist...")
|
||||
else:
|
||||
logger.info(f"Pair {pair} in your blacklist. Removing it from whitelist...")
|
||||
pairlist.remove(pair)
|
||||
return pairlist
|
||||
|
||||
def create_pair_list(self, pairs: List[str], timeframe: str = None) -> ListPairsWithTimeframes:
|
||||
"""
|
||||
Create list of pair tuples with (pair, ticker_interval)
|
||||
|
|
Loading…
Reference in New Issue
Block a user