From eaf3fd80c591889d30f882ed110cd2a032b13bef Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 9 Nov 2019 07:19:46 +0100 Subject: [PATCH] Allow blacklist-verification from all pairlists --- freqtrade/pairlist/IPairList.py | 13 ++++++++++++- freqtrade/pairlist/VolumePairList.py | 6 ++++-- freqtrade/pairlist/pairlistmanager.py | 15 +++------------ freqtrade/resolvers/pairlist_resolver.py | 3 ++- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/freqtrade/pairlist/IPairList.py b/freqtrade/pairlist/IPairList.py index 366a49bae..b666b12f2 100644 --- a/freqtrade/pairlist/IPairList.py +++ b/freqtrade/pairlist/IPairList.py @@ -6,6 +6,7 @@ Provides lists as configured in config.json """ import logging from abc import ABC, abstractmethod, abstractproperty +from copy import deepcopy from typing import Dict, List from freqtrade.exchange import market_is_active @@ -15,8 +16,9 @@ logger = logging.getLogger(__name__) class IPairList(ABC): - def __init__(self, exchange, config, pairlistconfig: dict) -> None: + def __init__(self, exchange, pairlistmanager, config, pairlistconfig: dict) -> None: self._exchange = exchange + self._pairlistmanager = pairlistmanager self._config = config self._pairlistconfig = pairlistconfig @@ -54,6 +56,15 @@ class IPairList(ABC): :return: new whitelist """ + @staticmethod + def _verify_blacklist(self, pairlist: List[str]) -> List[str]: + + for pair in deepcopy(pairlist): + if pair in self._pairlistmanager.blacklist: + logger.warning(f"Pair {pair} in your blacklist. Removing it from whitelist...") + pairlist.remove(pair) + return pairlist + def _whitelist_for_active_markets(self, whitelist: List[str]) -> List[str]: """ Check available markets and remove pair from whitelist if necessary diff --git a/freqtrade/pairlist/VolumePairList.py b/freqtrade/pairlist/VolumePairList.py index ba32c8681..77bdf472d 100644 --- a/freqtrade/pairlist/VolumePairList.py +++ b/freqtrade/pairlist/VolumePairList.py @@ -85,7 +85,9 @@ class VolumePairList(IPairList): sorted_tickers = sorted(tickers, reverse=True, key=lambda t: t[key]) # Validate whitelist to only have active market pairs pairs = self._whitelist_for_active_markets([s['symbol'] for s in sorted_tickers]) - - logger.info(f"Searching {self._number_pairs} pairs: {pairs[:self._number_pairs]}") + pairs = self._verify_blacklist(pairs) + # Limit to X number of pairs + pairs = pairs[:self._number_pairs] + logger.info(f"Searching {self._number_pairs} pairs: {pairs}") return pairs diff --git a/freqtrade/pairlist/pairlistmanager.py b/freqtrade/pairlist/pairlistmanager.py index d3532ee54..b1681afef 100644 --- a/freqtrade/pairlist/pairlistmanager.py +++ b/freqtrade/pairlist/pairlistmanager.py @@ -5,7 +5,6 @@ Provides lists as configured in config.json """ import logging -from copy import deepcopy from typing import List from freqtrade.pairlist.IPairList import IPairList @@ -25,7 +24,7 @@ class PairListManager(): self._tickers_needed = False for pl in self._config.get('pairlists', [{'method': "StaticPairList"}]): pairl = PairListResolver(pl.get('method'), - exchange, config, + exchange, self, config, pl.get('config')).pairlist self._tickers_needed = pairl.needstickers or self._tickers_needed self._pairlists.append(pairl) @@ -57,18 +56,10 @@ class PairListManager(): if self._tickers_needed: tickers = self._exchange.get_tickers() + # Process all pairlists in chain for pl in self._pairlists: - pl.filter_pairlist(pairlist, tickers) + pairlist = pl.filter_pairlist(pairlist, tickers) # Validation against blacklist happens after the pairlists to ensure blacklist is respected. pairlist = self.verify_blacklist(pairlist, self.blacklist) self._whitelist = pairlist - - @staticmethod - def verify_blacklist(pairlist: List[str], blacklist: List[str]) -> List[str]: - - for pair in deepcopy(pairlist): - if pair in blacklist: - logger.warning(f"Pair {pair} in your blacklist. Removing it from whitelist...") - pairlist.remove(pair) - return pairlist diff --git a/freqtrade/resolvers/pairlist_resolver.py b/freqtrade/resolvers/pairlist_resolver.py index db00f6515..a37d7dc05 100644 --- a/freqtrade/resolvers/pairlist_resolver.py +++ b/freqtrade/resolvers/pairlist_resolver.py @@ -20,13 +20,14 @@ class PairListResolver(IResolver): __slots__ = ['pairlist'] - def __init__(self, pairlist_name: str, exchange, config: dict, pairlistconfig) -> None: + def __init__(self, pairlist_name: str, exchange, pairlistmanager, config: dict, pairlistconfig) -> None: """ Load the custom class from config parameter :param config: configuration dictionary or None """ self.pairlist = self._load_pairlist(pairlist_name, config, kwargs={'exchange': exchange, + 'pairlistmanager': pairlistmanager, 'config': config, 'pairlistconfig': pairlistconfig})