pass pairlist position into the pairlists

This commit is contained in:
Matthias 2019-11-09 15:04:04 +01:00
parent ae35649366
commit 7ff61f12e9
7 changed files with 39 additions and 20 deletions

View File

@ -16,11 +16,20 @@ logger = logging.getLogger(__name__)
class IPairList(ABC): class IPairList(ABC):
def __init__(self, exchange, pairlistmanager, config, pairlistconfig: dict) -> None: def __init__(self, exchange, pairlistmanager, config, pairlistconfig: dict,
pairlist_pos: int) -> None:
"""
:param exchange: Exchange instance
:param pairlistmanager: Instanciating Pairlist manager
:param config: Global bot configuration
:param pairlistconfig: Configuration for this pairlist - can be empty.
:param pairlist_pos: Position of the filter in the pairlist-filter-list
"""
self._exchange = exchange self._exchange = exchange
self._pairlistmanager = pairlistmanager self._pairlistmanager = pairlistmanager
self._config = config self._config = config
self._pairlistconfig = pairlistconfig self._pairlistconfig = pairlistconfig
self._pairlist_pos = pairlist_pos
@property @property
def name(self) -> str: def name(self) -> str:

View File

@ -9,8 +9,9 @@ logger = logging.getLogger(__name__)
class LowPriceFilter(IPairList): class LowPriceFilter(IPairList):
def __init__(self, exchange, pairlistmanager, config, pairlistconfig: dict) -> None: def __init__(self, exchange, pairlistmanager, config, pairlistconfig: dict,
super().__init__(exchange, pairlistmanager, config, pairlistconfig) pairlist_pos: int) -> None:
super().__init__(exchange, pairlistmanager, config, pairlistconfig, pairlist_pos)
self._low_price_percent = pairlistconfig.get('low_price_percent', 0) self._low_price_percent = pairlistconfig.get('low_price_percent', 0)

View File

@ -14,9 +14,6 @@ logger = logging.getLogger(__name__)
class StaticPairList(IPairList): class StaticPairList(IPairList):
def __init__(self, exchange, pairlistmanager, config, pairlistconfig: dict) -> None:
super().__init__(exchange, pairlistmanager, config, pairlistconfig)
@property @property
def needstickers(self) -> bool: def needstickers(self) -> bool:
""" """

View File

@ -18,8 +18,9 @@ SORT_VALUES = ['askVolume', 'bidVolume', 'quoteVolume']
class VolumePairList(IPairList): class VolumePairList(IPairList):
def __init__(self, exchange, pairlistmanager, config, pairlistconfig: dict) -> None: def __init__(self, exchange, pairlistmanager, config, pairlistconfig: dict,
super().__init__(exchange, pairlistmanager, config, pairlistconfig) pairlist_pos: int) -> None:
super().__init__(exchange, pairlistmanager, config, pairlistconfig, pairlist_pos)
if 'number_assets' not in self._pairlistconfig: if 'number_assets' not in self._pairlistconfig:
raise OperationalException( raise OperationalException(
@ -85,11 +86,18 @@ class VolumePairList(IPairList):
:return: List of pairs :return: List of pairs
""" """
# check length so that we make sure that '/' is actually in the string if self._pairlist_pos == 0:
tickers = [v for k, v in tickers.items() # If VolumePairList is the first in the list, use fresh pairlist
if (len(k.split('/')) == 2 and k.split('/')[1] == base_currency # check length so that we make sure that '/' is actually in the string
and v[key] is not None)] filtered_tickers = [v for k, v in tickers.items()
sorted_tickers = sorted(tickers, reverse=True, key=lambda t: t[key]) if (len(k.split('/')) == 2 and k.split('/')[1] == base_currency
and v[key] is not None)]
else:
# If other pairlist is in front, use the incomming pairlist.
filtered_tickers = [v for k, v in tickers.items() if k in pairlist]
sorted_tickers = sorted(filtered_tickers, reverse=True, key=lambda t: t[key])
# Validate whitelist to only have active market pairs # Validate whitelist to only have active market pairs
pairs = self._whitelist_for_active_markets([s['symbol'] for s in sorted_tickers]) pairs = self._whitelist_for_active_markets([s['symbol'] for s in sorted_tickers])
pairs = self._verify_blacklist(pairs) pairs = self._verify_blacklist(pairs)

View File

@ -23,14 +23,17 @@ class PairListManager():
self._blacklist = self._config['exchange'].get('pair_blacklist', []) self._blacklist = self._config['exchange'].get('pair_blacklist', [])
self._pairlists: List[IPairList] = [] self._pairlists: List[IPairList] = []
self._tickers_needed = False self._tickers_needed = False
for pl in self._config.get('pairlists', None): for pl in self._config.get('pairlists', None):
if 'method' not in pl: if 'method' not in pl:
logger.warning(f"No method in {pl}") logger.warning(f"No method in {pl}")
continue continue
pairl = PairListResolver(pl.get('method'), pairl = PairListResolver(pl.get('method'),
exchange, self, config, exchange=exchange,
pl.get('config')).pairlist pairlistmanager=self,
config=config,
pairlistconfig=pl.get('config'),
pairlist_pos=len(self._pairlists)
).pairlist
self._tickers_needed = pairl.needstickers or self._tickers_needed self._tickers_needed = pairl.needstickers or self._tickers_needed
self._pairlists.append(pairl) self._pairlists.append(pairl)
@ -67,7 +70,7 @@ class PairListManager():
def refresh_pairlist(self) -> None: def refresh_pairlist(self) -> None:
""" """
Run pairlist through all pairlists. Run pairlist through all configured pairlists.
""" """
pairlist = self._whitelist.copy() pairlist = self._whitelist.copy()

View File

@ -21,7 +21,7 @@ class PairListResolver(IResolver):
__slots__ = ['pairlist'] __slots__ = ['pairlist']
def __init__(self, pairlist_name: str, exchange, pairlistmanager, def __init__(self, pairlist_name: str, exchange, pairlistmanager,
config: dict, pairlistconfig) -> None: config: dict, pairlistconfig: dict, pairlist_pos: int) -> None:
""" """
Load the custom class from config parameter Load the custom class from config parameter
:param config: configuration dictionary or None :param config: configuration dictionary or None
@ -30,7 +30,8 @@ class PairListResolver(IResolver):
kwargs={'exchange': exchange, kwargs={'exchange': exchange,
'pairlistmanager': pairlistmanager, 'pairlistmanager': pairlistmanager,
'config': config, 'config': config,
'pairlistconfig': pairlistconfig}) 'pairlistconfig': pairlistconfig,
'pairlist_pos': pairlist_pos})
def _load_pairlist( def _load_pairlist(
self, pairlist_name: str, config: dict, kwargs: dict) -> IPairList: self, pairlist_name: str, config: dict, kwargs: dict) -> IPairList:

View File

@ -55,7 +55,7 @@ def test_load_pairlist_noexist(mocker, markets, default_conf):
with pytest.raises(OperationalException, with pytest.raises(OperationalException,
match=r"Impossible to load Pairlist 'NonexistingPairList'. " match=r"Impossible to load Pairlist 'NonexistingPairList'. "
r"This class does not exist or contains Python code errors."): r"This class does not exist or contains Python code errors."):
PairListResolver('NonexistingPairList', bot.exchange, plm, default_conf, {}) PairListResolver('NonexistingPairList', bot.exchange, plm, default_conf, {}, 1)
def test_refresh_market_pair_not_in_whitelist(mocker, markets, static_pl_conf): def test_refresh_market_pair_not_in_whitelist(mocker, markets, static_pl_conf):