2018-12-05 19:44:56 +00:00
|
|
|
# pragma pylint: disable=attribute-defined-outside-init
|
|
|
|
|
|
|
|
"""
|
2019-10-18 20:29:19 +00:00
|
|
|
This module load custom pairlists
|
2018-12-05 19:44:56 +00:00
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
from pathlib import Path
|
|
|
|
|
2019-07-12 20:45:49 +00:00
|
|
|
from freqtrade import OperationalException
|
2018-12-05 19:44:56 +00:00
|
|
|
from freqtrade.pairlist.IPairList import IPairList
|
|
|
|
from freqtrade.resolvers import IResolver
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class PairListResolver(IResolver):
|
|
|
|
"""
|
2019-10-18 20:29:19 +00:00
|
|
|
This class contains all the logic to load custom PairList class
|
2018-12-05 19:44:56 +00:00
|
|
|
"""
|
|
|
|
|
2019-12-23 08:56:12 +00:00
|
|
|
@staticmethod
|
|
|
|
def load_pairlist(pairlist_name: str, exchange, pairlistmanager,
|
|
|
|
config: dict, pairlistconfig: dict, pairlist_pos: int) -> IPairList:
|
2018-12-05 19:44:56 +00:00
|
|
|
"""
|
2019-12-23 08:56:12 +00:00
|
|
|
Load the pairlist with pairlist_name
|
|
|
|
: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
|
2018-12-05 19:44:56 +00:00
|
|
|
"""
|
2019-12-23 08:56:12 +00:00
|
|
|
|
|
|
|
return PairListResolver._load_pairlist(pairlist_name, config,
|
|
|
|
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:
|
2018-12-05 19:44:56 +00:00
|
|
|
"""
|
|
|
|
Search and loads the specified pairlist.
|
|
|
|
:param pairlist_name: name of the module to import
|
2019-07-28 13:02:11 +00:00
|
|
|
:param config: configuration dictionary
|
2018-12-05 19:44:56 +00:00
|
|
|
:param extra_dir: additional directory to search for the given pairlist
|
|
|
|
:return: PairList instance or None
|
|
|
|
"""
|
|
|
|
current_path = Path(__file__).parent.parent.joinpath('pairlist').resolve()
|
|
|
|
|
2019-12-23 08:56:12 +00:00
|
|
|
abs_paths = IResolver.build_search_paths(config, current_path=current_path,
|
|
|
|
user_subdir=None, extra_dir=None)
|
2018-12-05 19:44:56 +00:00
|
|
|
|
2019-12-23 08:56:12 +00:00
|
|
|
pairlist = IResolver._load_object(paths=abs_paths, object_type=IPairList,
|
|
|
|
object_name=pairlist_name, kwargs=kwargs)
|
2019-07-21 13:03:12 +00:00
|
|
|
if pairlist:
|
|
|
|
return pairlist
|
2019-07-12 20:45:49 +00:00
|
|
|
raise OperationalException(
|
|
|
|
f"Impossible to load Pairlist '{pairlist_name}'. This class does not exist "
|
|
|
|
"or contains Python code errors."
|
2018-12-05 19:44:56 +00:00
|
|
|
)
|