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
|
|
|
|
"""
|
|
|
|
self.pairlist = self._load_pairlist(pairlist_name, kwargs={'freqtrade': freqtrade,
|
|
|
|
'config': config})
|
|
|
|
|
|
|
|
def _load_pairlist(
|
|
|
|
self, pairlist_name: str, kwargs: dict) -> IPairList:
|
|
|
|
"""
|
|
|
|
Search and loads the specified pairlist.
|
|
|
|
:param pairlist_name: name of the module to import
|
|
|
|
: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 = [
|
2019-07-17 18:53:29 +00:00
|
|
|
Path.cwd().joinpath('user_data/pairlist'),
|
2018-12-05 19:44:56 +00:00
|
|
|
current_path,
|
|
|
|
]
|
|
|
|
|
2019-07-21 13:25:48 +00:00
|
|
|
pairlist = self._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
|
|
|
)
|