refactor: simplify some checks
This commit is contained in:
@@ -23,8 +23,8 @@ def start_create_userdir(args: dict[str, Any]) -> None:
|
|||||||
"""
|
"""
|
||||||
from freqtrade.configuration.directory_operations import copy_sample_files, create_userdata_dir
|
from freqtrade.configuration.directory_operations import copy_sample_files, create_userdata_dir
|
||||||
|
|
||||||
if "user_data_dir" in args and args["user_data_dir"]:
|
if user_data_dir := args.get("user_data_dir"):
|
||||||
userdir = create_userdata_dir(args["user_data_dir"], create_dir=True)
|
userdir = create_userdata_dir(user_data_dir, create_dir=True)
|
||||||
copy_sample_files(userdir, overwrite=args["reset"])
|
copy_sample_files(userdir, overwrite=args["reset"])
|
||||||
else:
|
else:
|
||||||
logger.warning("`create-userdir` requires --userdir to be set.")
|
logger.warning("`create-userdir` requires --userdir to be set.")
|
||||||
@@ -85,22 +85,22 @@ def start_new_strategy(args: dict[str, Any]) -> None:
|
|||||||
|
|
||||||
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
|
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
|
||||||
|
|
||||||
if "strategy" in args and args["strategy"]:
|
if strategy := args.get("strategy"):
|
||||||
if "strategy_path" in args and args["strategy_path"]:
|
if strategy_path := args.get("strategy_path"):
|
||||||
strategy_dir = Path(args["strategy_path"])
|
strategy_dir = Path(strategy_path)
|
||||||
else:
|
else:
|
||||||
strategy_dir = config["user_data_dir"] / USERPATH_STRATEGIES
|
strategy_dir = config["user_data_dir"] / USERPATH_STRATEGIES
|
||||||
if not strategy_dir.is_dir():
|
if not strategy_dir.is_dir():
|
||||||
logger.info(f"Creating strategy directory {strategy_dir}")
|
logger.info(f"Creating strategy directory {strategy_dir}")
|
||||||
strategy_dir.mkdir(parents=True)
|
strategy_dir.mkdir(parents=True)
|
||||||
new_path = strategy_dir / (args["strategy"] + ".py")
|
new_path = strategy_dir / (strategy + ".py")
|
||||||
|
|
||||||
if new_path.exists():
|
if new_path.exists():
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
f"`{new_path}` already exists. Please choose another Strategy Name."
|
f"`{new_path}` already exists. Please choose another Strategy Name."
|
||||||
)
|
)
|
||||||
|
|
||||||
deploy_new_strategy(args["strategy"], new_path, args["template"])
|
deploy_new_strategy(strategy, new_path, args["template"])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ConfigurationError("`new-strategy` requires --strategy to be set.")
|
raise ConfigurationError("`new-strategy` requires --strategy to be set.")
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ class Configuration:
|
|||||||
{"verbosity": safe_value_fallback(self.args, "verbosity", default_value=0)}
|
{"verbosity": safe_value_fallback(self.args, "verbosity", default_value=0)}
|
||||||
)
|
)
|
||||||
|
|
||||||
if "logfile" in self.args and self.args["logfile"]:
|
if self.args.get("logfile"):
|
||||||
config.update({"logfile": self.args["logfile"]})
|
config.update({"logfile": self.args["logfile"]})
|
||||||
|
|
||||||
if "print_colorized" in self.args and not self.args["print_colorized"]:
|
if "print_colorized" in self.args and not self.args["print_colorized"]:
|
||||||
@@ -187,7 +187,7 @@ class Configuration:
|
|||||||
logger.warning("`force_entry_enable` RPC message enabled.")
|
logger.warning("`force_entry_enable` RPC message enabled.")
|
||||||
|
|
||||||
# Support for sd_notify
|
# Support for sd_notify
|
||||||
if "sd_notify" in self.args and self.args["sd_notify"]:
|
if self.args.get("sd_notify"):
|
||||||
config["internals"].update({"sd_notify": True})
|
config["internals"].update({"sd_notify": True})
|
||||||
|
|
||||||
def _process_datadir_options(self, config: Config) -> None:
|
def _process_datadir_options(self, config: Config) -> None:
|
||||||
@@ -196,14 +196,14 @@ class Configuration:
|
|||||||
--user-data, --datadir
|
--user-data, --datadir
|
||||||
"""
|
"""
|
||||||
# Check exchange parameter here - otherwise `datadir` might be wrong.
|
# Check exchange parameter here - otherwise `datadir` might be wrong.
|
||||||
if "exchange" in self.args and self.args["exchange"]:
|
if self.args.get("exchange"):
|
||||||
config["exchange"]["name"] = self.args["exchange"]
|
config["exchange"]["name"] = self.args["exchange"]
|
||||||
logger.info(f"Using exchange {config['exchange']['name']}")
|
logger.info(f"Using exchange {config['exchange']['name']}")
|
||||||
|
|
||||||
if "pair_whitelist" not in config["exchange"]:
|
if "pair_whitelist" not in config["exchange"]:
|
||||||
config["exchange"]["pair_whitelist"] = []
|
config["exchange"]["pair_whitelist"] = []
|
||||||
|
|
||||||
if "user_data_dir" in self.args and self.args["user_data_dir"]:
|
if self.args.get("user_data_dir"):
|
||||||
config.update({"user_data_dir": self.args["user_data_dir"]})
|
config.update({"user_data_dir": self.args["user_data_dir"]})
|
||||||
elif "user_data_dir" not in config:
|
elif "user_data_dir" not in config:
|
||||||
# Default to cwd/user_data (legacy option ...)
|
# Default to cwd/user_data (legacy option ...)
|
||||||
@@ -251,7 +251,7 @@ class Configuration:
|
|||||||
logstring="Parameter --enable-protections detected, enabling Protections. ...",
|
logstring="Parameter --enable-protections detected, enabling Protections. ...",
|
||||||
)
|
)
|
||||||
|
|
||||||
if "max_open_trades" in self.args and self.args["max_open_trades"]:
|
if self.args.get("max_open_trades"):
|
||||||
config.update({"max_open_trades": self.args["max_open_trades"]})
|
config.update({"max_open_trades": self.args["max_open_trades"]})
|
||||||
logger.info(
|
logger.info(
|
||||||
"Parameter --max-open-trades detected, overriding max_open_trades to: %s ...",
|
"Parameter --max-open-trades detected, overriding max_open_trades to: %s ...",
|
||||||
@@ -314,7 +314,7 @@ class Configuration:
|
|||||||
self._args_to_config_loop(config, configurations)
|
self._args_to_config_loop(config, configurations)
|
||||||
|
|
||||||
# Edge section:
|
# Edge section:
|
||||||
if "stoploss_range" in self.args and self.args["stoploss_range"]:
|
if self.args.get("stoploss_range"):
|
||||||
txt_range = ast.literal_eval(self.args["stoploss_range"])
|
txt_range = ast.literal_eval(self.args["stoploss_range"])
|
||||||
config["edge"].update({"stoploss_range_min": txt_range[0]})
|
config["edge"].update({"stoploss_range_min": txt_range[0]})
|
||||||
config["edge"].update({"stoploss_range_max": txt_range[1]})
|
config["edge"].update({"stoploss_range_max": txt_range[1]})
|
||||||
@@ -493,7 +493,7 @@ class Configuration:
|
|||||||
config["exchange"]["pair_whitelist"] = config["pairs"]
|
config["exchange"]["pair_whitelist"] = config["pairs"]
|
||||||
return
|
return
|
||||||
|
|
||||||
if "pairs_file" in self.args and self.args["pairs_file"]:
|
if self.args.get("pairs_file"):
|
||||||
pairs_file = Path(self.args["pairs_file"])
|
pairs_file = Path(self.args["pairs_file"])
|
||||||
logger.info(f'Reading pairs file "{pairs_file}".')
|
logger.info(f'Reading pairs file "{pairs_file}".')
|
||||||
# Download pairs from the pairs file if no config is specified
|
# Download pairs from the pairs file if no config is specified
|
||||||
@@ -505,7 +505,7 @@ class Configuration:
|
|||||||
config["pairs"].sort()
|
config["pairs"].sort()
|
||||||
return
|
return
|
||||||
|
|
||||||
if "config" in self.args and self.args["config"]:
|
if self.args.get("config"):
|
||||||
logger.info("Using pairlist from configuration.")
|
logger.info("Using pairlist from configuration.")
|
||||||
config["pairs"] = config.get("exchange", {}).get("pair_whitelist")
|
config["pairs"] = config.get("exchange", {}).get("pair_whitelist")
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user