Recursively search subdirectories in user_data/strategies for a strategy
This commit is contained in:
parent
ddb0254999
commit
6df15a7af9
@ -44,7 +44,7 @@ class IResolver:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def build_search_paths(cls, config: Dict[str, Any], user_subdir: Optional[str] = None,
|
def build_search_paths(cls, config: Dict[str, Any], user_subdir: Optional[str] = None,
|
||||||
extra_dir: Optional[str] = None) -> List[Path]:
|
extra_dirs: Optional[List[str]] = None) -> List[Path]:
|
||||||
|
|
||||||
abs_paths: List[Path] = []
|
abs_paths: List[Path] = []
|
||||||
if cls.initial_search_path:
|
if cls.initial_search_path:
|
||||||
@ -53,9 +53,10 @@ class IResolver:
|
|||||||
if user_subdir:
|
if user_subdir:
|
||||||
abs_paths.insert(0, config['user_data_dir'].joinpath(user_subdir))
|
abs_paths.insert(0, config['user_data_dir'].joinpath(user_subdir))
|
||||||
|
|
||||||
if extra_dir:
|
if extra_dirs:
|
||||||
# Add extra directory to the top of the search paths
|
# Add extra directory to the top of the search paths
|
||||||
abs_paths.insert(0, Path(extra_dir).resolve())
|
for dir in extra_dirs:
|
||||||
|
abs_paths.insert(0, Path(dir).resolve())
|
||||||
|
|
||||||
return abs_paths
|
return abs_paths
|
||||||
|
|
||||||
@ -164,9 +165,13 @@ class IResolver:
|
|||||||
:return: Object instance or None
|
:return: Object instance or None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
extra_dirs: List[str] = []
|
||||||
|
if extra_dir:
|
||||||
|
extra_dirs.append(extra_dir)
|
||||||
|
|
||||||
abs_paths = cls.build_search_paths(config,
|
abs_paths = cls.build_search_paths(config,
|
||||||
user_subdir=cls.user_subdir,
|
user_subdir=cls.user_subdir,
|
||||||
extra_dir=extra_dir)
|
extra_dirs=extra_dirs)
|
||||||
|
|
||||||
found_object = cls._load_object(paths=abs_paths, object_name=object_name,
|
found_object = cls._load_object(paths=abs_paths, object_name=object_name,
|
||||||
kwargs=kwargs)
|
kwargs=kwargs)
|
||||||
|
@ -7,8 +7,9 @@ import logging
|
|||||||
import tempfile
|
import tempfile
|
||||||
from base64 import urlsafe_b64decode
|
from base64 import urlsafe_b64decode
|
||||||
from inspect import getfullargspec
|
from inspect import getfullargspec
|
||||||
|
from os import walk
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
from freqtrade.constants import REQUIRED_ORDERTIF, REQUIRED_ORDERTYPES, USERPATH_STRATEGIES
|
from freqtrade.constants import REQUIRED_ORDERTIF, REQUIRED_ORDERTYPES, USERPATH_STRATEGIES
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
@ -166,10 +167,15 @@ class StrategyResolver(IResolver):
|
|||||||
:param extra_dir: additional directory to search for the given strategy
|
:param extra_dir: additional directory to search for the given strategy
|
||||||
:return: Strategy instance or None
|
:return: Strategy instance or None
|
||||||
"""
|
"""
|
||||||
|
extra_dirs: List[str] = [
|
||||||
|
path[0] for path in walk(f"{config['user_data_dir']}/{USERPATH_STRATEGIES}")
|
||||||
|
] # sub-directories
|
||||||
|
if extra_dir:
|
||||||
|
extra_dirs.append(extra_dir)
|
||||||
|
|
||||||
abs_paths = StrategyResolver.build_search_paths(config,
|
abs_paths = StrategyResolver.build_search_paths(config,
|
||||||
user_subdir=USERPATH_STRATEGIES,
|
user_subdir=USERPATH_STRATEGIES,
|
||||||
extra_dir=extra_dir)
|
extra_dirs=extra_dirs)
|
||||||
|
|
||||||
if ":" in strategy_name:
|
if ":" in strategy_name:
|
||||||
logger.info("loading base64 encoded strategy")
|
logger.info("loading base64 encoded strategy")
|
||||||
|
Loading…
Reference in New Issue
Block a user