stable/freqtrade/resolvers/pairlist_resolver.py

53 lines
1.9 KiB
Python
Raw Normal View History

2018-12-05 19:44:56 +00:00
# pragma pylint: disable=attribute-defined-outside-init
"""
This module load custom hyperopts
"""
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):
"""
This class contains all the logic to load custom hyperopt class
"""
__slots__ = ['pairlist']
def __init__(self, pairlist_name: str, freqtrade, config: dict) -> None:
"""
Load the custom class from config parameter
:param config: configuration dictionary or None
"""
2019-07-28 12:49:34 +00:00
self.pairlist = self._load_pairlist(pairlist_name, config, kwargs={'freqtrade': freqtrade,
'config': config})
2018-12-05 19:44:56 +00:00
def _load_pairlist(
2019-07-28 12:49:34 +00:00
self, 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()
abs_paths = self.build_search_paths(config, current_path=current_path,
user_subdir='pairlist', extra_dir=None)
2018-12-05 19:44:56 +00:00
pairlist = self._load_object(paths=abs_paths, object_type=IPairList,
object_name=pairlist_name, kwargs=kwargs)
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
)