Use constant for Strategy and hyperopt userdirpaths
This commit is contained in:
parent
03cdfe8cae
commit
cbb187e9b9
@ -22,12 +22,15 @@ AVAILABLE_PAIRLISTS = ['StaticPairList', 'VolumePairList', 'PrecisionFilter', 'P
|
|||||||
DRY_RUN_WALLET = 999.9
|
DRY_RUN_WALLET = 999.9
|
||||||
MATH_CLOSE_PREC = 1e-14 # Precision used for float comparisons
|
MATH_CLOSE_PREC = 1e-14 # Precision used for float comparisons
|
||||||
|
|
||||||
# Soure files with destination directories
|
USERPATH_HYPEROPTS = 'hyperopts'
|
||||||
|
USERPATH_STRATEGY = 'strategies'
|
||||||
|
|
||||||
|
# Soure files with destination directories within user-directory
|
||||||
USER_DATA_FILES = {
|
USER_DATA_FILES = {
|
||||||
'sample_strategy.py': 'strategies',
|
'sample_strategy.py': USERPATH_STRATEGY,
|
||||||
'sample_hyperopt_advanced.py': 'hyperopts',
|
'sample_hyperopt_advanced.py': USERPATH_HYPEROPTS,
|
||||||
'sample_hyperopt_loss.py': 'hyperopts',
|
'sample_hyperopt_loss.py': USERPATH_HYPEROPTS,
|
||||||
'sample_hyperopt.py': 'hyperopts',
|
'sample_hyperopt.py': USERPATH_HYPEROPTS,
|
||||||
'strategy_analysis_example.ipynb': 'notebooks',
|
'strategy_analysis_example.ipynb': 'notebooks',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ def plural(num, singular: str, plural: str = None) -> str:
|
|||||||
return singular if (num == 1 or num == -1) else plural or singular + 's'
|
return singular if (num == 1 or num == -1) else plural or singular + 's'
|
||||||
|
|
||||||
|
|
||||||
def render_template(template: str, arguments: dict):
|
def render_template(templatefile: str, arguments: dict):
|
||||||
|
|
||||||
from jinja2 import Environment, PackageLoader, select_autoescape
|
from jinja2 import Environment, PackageLoader, select_autoescape
|
||||||
|
|
||||||
@ -137,6 +137,6 @@ def render_template(template: str, arguments: dict):
|
|||||||
loader=PackageLoader('freqtrade', 'templates'),
|
loader=PackageLoader('freqtrade', 'templates'),
|
||||||
autoescape=select_autoescape(['html', 'xml'])
|
autoescape=select_autoescape(['html', 'xml'])
|
||||||
)
|
)
|
||||||
template = env.get_template(template)
|
template = env.get_template(templatefile)
|
||||||
|
|
||||||
return template.render(**arguments)
|
return template.render(**arguments)
|
||||||
|
@ -8,7 +8,7 @@ from pathlib import Path
|
|||||||
from typing import Optional, Dict
|
from typing import Optional, Dict
|
||||||
|
|
||||||
from freqtrade import OperationalException
|
from freqtrade import OperationalException
|
||||||
from freqtrade.constants import DEFAULT_HYPEROPT_LOSS
|
from freqtrade.constants import DEFAULT_HYPEROPT_LOSS, USERPATH_HYPEROPTS
|
||||||
from freqtrade.optimize.hyperopt_interface import IHyperOpt
|
from freqtrade.optimize.hyperopt_interface import IHyperOpt
|
||||||
from freqtrade.optimize.hyperopt_loss_interface import IHyperOptLoss
|
from freqtrade.optimize.hyperopt_loss_interface import IHyperOptLoss
|
||||||
from freqtrade.resolvers import IResolver
|
from freqtrade.resolvers import IResolver
|
||||||
@ -58,7 +58,7 @@ class HyperOptResolver(IResolver):
|
|||||||
current_path = Path(__file__).parent.parent.joinpath('optimize').resolve()
|
current_path = Path(__file__).parent.parent.joinpath('optimize').resolve()
|
||||||
|
|
||||||
abs_paths = self.build_search_paths(config, current_path=current_path,
|
abs_paths = self.build_search_paths(config, current_path=current_path,
|
||||||
user_subdir='hyperopts', extra_dir=extra_dir)
|
user_subdir=USERPATH_HYPEROPTS, extra_dir=extra_dir)
|
||||||
|
|
||||||
hyperopt = self._load_object(paths=abs_paths, object_type=IHyperOpt,
|
hyperopt = self._load_object(paths=abs_paths, object_type=IHyperOpt,
|
||||||
object_name=hyperopt_name, kwargs={'config': config})
|
object_name=hyperopt_name, kwargs={'config': config})
|
||||||
@ -110,7 +110,7 @@ class HyperOptLossResolver(IResolver):
|
|||||||
current_path = Path(__file__).parent.parent.joinpath('optimize').resolve()
|
current_path = Path(__file__).parent.parent.joinpath('optimize').resolve()
|
||||||
|
|
||||||
abs_paths = self.build_search_paths(config, current_path=current_path,
|
abs_paths = self.build_search_paths(config, current_path=current_path,
|
||||||
user_subdir='hyperopts', extra_dir=extra_dir)
|
user_subdir=USERPATH_HYPEROPTS, extra_dir=extra_dir)
|
||||||
|
|
||||||
hyperoptloss = self._load_object(paths=abs_paths, object_type=IHyperOptLoss,
|
hyperoptloss = self._load_object(paths=abs_paths, object_type=IHyperOptLoss,
|
||||||
object_name=hyper_loss_name)
|
object_name=hyper_loss_name)
|
||||||
|
@ -129,7 +129,8 @@ class StrategyResolver(IResolver):
|
|||||||
current_path = Path(__file__).parent.parent.joinpath('strategy').resolve()
|
current_path = Path(__file__).parent.parent.joinpath('strategy').resolve()
|
||||||
|
|
||||||
abs_paths = self.build_search_paths(config, current_path=current_path,
|
abs_paths = self.build_search_paths(config, current_path=current_path,
|
||||||
user_subdir='strategies', extra_dir=extra_dir)
|
user_subdir=constants.USERPATH_STRATEGY,
|
||||||
|
extra_dir=extra_dir)
|
||||||
|
|
||||||
if ":" in strategy_name:
|
if ":" in strategy_name:
|
||||||
logger.info("loading base64 encoded strategy")
|
logger.info("loading base64 encoded strategy")
|
||||||
|
@ -4,7 +4,7 @@ from functools import reduce
|
|||||||
from typing import Any, Callable, Dict, List
|
from typing import Any, Callable, Dict, List
|
||||||
|
|
||||||
import numpy as np # noqa
|
import numpy as np # noqa
|
||||||
import talib.abstract as ta
|
import talib.abstract as ta # noqa
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
from skopt.space import Categorical, Dimension, Integer, Real # noqa
|
from skopt.space import Categorical, Dimension, Integer, Real # noqa
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ from freqtrade.configuration import (Configuration, TimeRange,
|
|||||||
remove_credentials)
|
remove_credentials)
|
||||||
from freqtrade.configuration.directory_operations import (copy_sample_files,
|
from freqtrade.configuration.directory_operations import (copy_sample_files,
|
||||||
create_userdata_dir)
|
create_userdata_dir)
|
||||||
|
from freqtrade.constants import USERPATH_HYPEROPTS, USERPATH_STRATEGY
|
||||||
from freqtrade.data.history import (convert_trades_to_ohlcv,
|
from freqtrade.data.history import (convert_trades_to_ohlcv,
|
||||||
refresh_backtest_ohlcv_data,
|
refresh_backtest_ohlcv_data,
|
||||||
refresh_backtest_trades_data)
|
refresh_backtest_trades_data)
|
||||||
@ -98,13 +99,13 @@ def start_new_strategy(args: Dict[str, Any]) -> None:
|
|||||||
if args["strategy"] == "DefaultStrategy":
|
if args["strategy"] == "DefaultStrategy":
|
||||||
raise OperationalException("DefaultStrategy is not allowed as name.")
|
raise OperationalException("DefaultStrategy is not allowed as name.")
|
||||||
|
|
||||||
new_path = config['user_data_dir'] / "strategies" / (args["strategy"] + ".py")
|
new_path = config['user_data_dir'] / USERPATH_STRATEGY / (args["strategy"] + ".py")
|
||||||
|
|
||||||
if new_path.exists():
|
if new_path.exists():
|
||||||
raise OperationalException(f"`{new_path}` already exists. "
|
raise OperationalException(f"`{new_path}` already exists. "
|
||||||
"Please choose another Strategy Name.")
|
"Please choose another Strategy Name.")
|
||||||
|
|
||||||
strategy_text = render_template(template='base_strategy.py.j2',
|
strategy_text = render_template(templatefile='base_strategy.py.j2',
|
||||||
arguments={"strategy": args["strategy"]})
|
arguments={"strategy": args["strategy"]})
|
||||||
|
|
||||||
logger.info(f"Writing strategy to `{new_path}`.")
|
logger.info(f"Writing strategy to `{new_path}`.")
|
||||||
@ -121,13 +122,13 @@ def start_new_hyperopt(args: Dict[str, Any]) -> None:
|
|||||||
if args["hyperopt"] == "DefaultHyperopt":
|
if args["hyperopt"] == "DefaultHyperopt":
|
||||||
raise OperationalException("DefaultHyperopt is not allowed as name.")
|
raise OperationalException("DefaultHyperopt is not allowed as name.")
|
||||||
|
|
||||||
new_path = config['user_data_dir'] / "hyperopts" / (args["hyperopt"] + ".py")
|
new_path = config['user_data_dir'] / USERPATH_HYPEROPTS / (args["hyperopt"] + ".py")
|
||||||
|
|
||||||
if new_path.exists():
|
if new_path.exists():
|
||||||
raise OperationalException(f"`{new_path}` already exists. "
|
raise OperationalException(f"`{new_path}` already exists. "
|
||||||
"Please choose another Strategy Name.")
|
"Please choose another Strategy Name.")
|
||||||
|
|
||||||
strategy_text = render_template(template='base_hyperopt.py.j2',
|
strategy_text = render_template(templatefile='base_hyperopt.py.j2',
|
||||||
arguments={"hyperopt": args["hyperopt"]})
|
arguments={"hyperopt": args["hyperopt"]})
|
||||||
|
|
||||||
logger.info(f"Writing hyperopt to `{new_path}`.")
|
logger.info(f"Writing hyperopt to `{new_path}`.")
|
||||||
|
Loading…
Reference in New Issue
Block a user