Convert PairlistResolver to static loader

This commit is contained in:
Matthias 2019-12-23 09:56:12 +01:00
parent 1c5f8070e5
commit 5fefa9e97c
3 changed files with 34 additions and 25 deletions

View File

@ -28,13 +28,13 @@ class PairListManager():
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.load_pairlist(pl.get('method'),
exchange=exchange, exchange=exchange,
pairlistmanager=self, pairlistmanager=self,
config=config, config=config,
pairlistconfig=pl, pairlistconfig=pl,
pairlist_pos=len(self._pairlists) 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)

View File

@ -18,23 +18,32 @@ class PairListResolver(IResolver):
This class contains all the logic to load custom PairList class This class contains all the logic to load custom PairList class
""" """
__slots__ = ['pairlist'] __slots__ = []
def __init__(self, pairlist_name: str, exchange, pairlistmanager, @staticmethod
config: dict, pairlistconfig: dict, pairlist_pos: int) -> None: def load_pairlist(pairlist_name: str, exchange, pairlistmanager,
config: dict, pairlistconfig: dict, pairlist_pos: int) -> IPairList:
""" """
Load the custom class from config parameter Load the pairlist with pairlist_name
:param config: configuration dictionary or None :param pairlist_name: Classname of the pairlist
:param exchange: Initialized exchange class
:param pairlistmanager: Initialized pairlist manager
:param config: configuration dictionary
:param pairlistconfig: Configuration dedicated to this pairlist
:param pairlist_pos: Position of the pairlist in the list of pairlists
:return: initialized Pairlist class
""" """
self.pairlist = self._load_pairlist(pairlist_name, config,
kwargs={'exchange': exchange,
'pairlistmanager': pairlistmanager,
'config': config,
'pairlistconfig': pairlistconfig,
'pairlist_pos': pairlist_pos})
def _load_pairlist( return PairListResolver._load_pairlist(pairlist_name, config,
self, pairlist_name: str, config: dict, kwargs: dict) -> IPairList: kwargs={'exchange': exchange,
'pairlistmanager': pairlistmanager,
'config': config,
'pairlistconfig': pairlistconfig,
'pairlist_pos': pairlist_pos})
@staticmethod
def _load_pairlist(pairlist_name: str, config: dict, kwargs: dict) -> IPairList:
""" """
Search and loads the specified pairlist. Search and loads the specified pairlist.
:param pairlist_name: name of the module to import :param pairlist_name: name of the module to import
@ -44,11 +53,11 @@ class PairListResolver(IResolver):
""" """
current_path = Path(__file__).parent.parent.joinpath('pairlist').resolve() current_path = Path(__file__).parent.parent.joinpath('pairlist').resolve()
abs_paths = self.build_search_paths(config, current_path=current_path, abs_paths = IResolver.build_search_paths(config, current_path=current_path,
user_subdir=None, extra_dir=None) user_subdir=None, extra_dir=None)
pairlist = self._load_object(paths=abs_paths, object_type=IPairList, pairlist = IResolver._load_object(paths=abs_paths, object_type=IPairList,
object_name=pairlist_name, kwargs=kwargs) object_name=pairlist_name, kwargs=kwargs)
if pairlist: if pairlist:
return pairlist return pairlist
raise OperationalException( raise OperationalException(

View File

@ -53,7 +53,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, {}, 1) PairListResolver.load_pairlist('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):