Merge branch 'freqtrade:develop' into feat/fix-max-drawdown-protection

This commit is contained in:
ABS
2026-02-23 10:36:08 +08:00
committed by GitHub
9 changed files with 384 additions and 320 deletions

View File

@@ -64,18 +64,15 @@ options:
--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]
Provide a space-separated list of strategies to
backtest. Please note that timeframe needs to be set
either in config or via command line. When using this
together with `--export trades`, the strategy-name is
injected into the filename (so `backtest-data.json`
becomes `backtest-data-SampleStrategy.json`
either in config or via command line.
--export {none,trades,signals}
Export backtest results (default: trades).
--backtest-filename, --export-filename PATH
Use this filename for backtest results.Example:
`--backtest-
filename=backtest_results_2020-09-27_16-20-48.json`.
Assumes either `user_data/backtest_results/` or
`--export-directory` as base directory.
DEPRECATED: This option is deprecated for backtesting
and will be removed in a future release. Using a
custom filename for backtest results is no longer
supported. Use `--backtest-directory` to specify the
directory.
--backtest-directory, --export-directory PATH
Directory to use for backtest results. Example:
`--export-directory=user_data/backtest_results/`.

View File

@@ -62,10 +62,7 @@ options:
--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]
Provide a space-separated list of strategies to
backtest. Please note that timeframe needs to be set
either in config or via command line. When using this
together with `--export trades`, the strategy-name is
injected into the filename (so `backtest-data.json`
becomes `backtest-data-SampleStrategy.json`
either in config or via command line.
--export {none,trades,signals}
Export backtest results (default: trades).
--backtest-filename, --export-filename PATH

View File

@@ -10,10 +10,7 @@ options:
--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]
Provide a space-separated list of strategies to
backtest. Please note that timeframe needs to be set
either in config or via command line. When using this
together with `--export trades`, the strategy-name is
injected into the filename (so `backtest-data.json`
becomes `backtest-data-SampleStrategy.json`
either in config or via command line.
--strategy-path PATH Specify additional strategy lookup path.
--recursive-strategy-search
Recursively search for a strategy in the strategies

View File

@@ -215,9 +215,7 @@ AVAILABLE_CLI_OPTIONS = {
"--strategy-list",
help="Provide a space-separated list of strategies to backtest. "
"Please note that timeframe needs to be set either in config "
"or via command line. When using this together with `--export trades`, "
"the strategy-name is injected into the filename "
"(so `backtest-data.json` becomes `backtest-data-SampleStrategy.json`",
"or via command line. ",
nargs="+",
),
"backtest_notes": Arg(
@@ -240,6 +238,14 @@ AVAILABLE_CLI_OPTIONS = {
"exportfilename": Arg(
"--backtest-filename",
"--export-filename",
fthelp={
"freqtrade backtesting": (
"DEPRECATED: This option is deprecated for backtesting and will be removed "
"in a future release. "
"Using a custom filename for backtest results is no longer supported. "
"Use `--backtest-directory` to specify the directory."
),
},
help="Use this filename for backtest results."
"Example: `--backtest-filename=backtest_results_2020-09-27_16-20-48.json`. "
"Assumes either `user_data/backtest_results/` or `--export-directory` as base directory.",

View File

@@ -221,30 +221,30 @@ class Configuration:
config, argname="exportfilename", logstring="Storing backtest results to {} ..."
)
config["exportfilename"] = Path(config["exportfilename"])
if config.get("exportdirectory") and Path(config["exportdirectory"]).is_dir():
logger.warning(
"DEPRECATED: Using `--export-filename` with directories is deprecated, "
"use `--backtest-directory` instead."
)
if config.get("exportdirectory") is None:
# Fallback - assign export-directory directly.
config["exportdirectory"] = config["exportfilename"]
if config.get("exportfilename"):
if Path(config["exportfilename"]).is_dir():
logger.warning(
"DEPRECATED: Using `--export-filename` with directories is deprecated, "
"use `--backtest-directory` instead."
)
if config.get("exportdirectory") is None:
# Fallback - assign export-directory directly.
config["exportdirectory"] = config["exportfilename"]
elif config.get("runmode") == RunMode.BACKTEST:
logger.warning(
"DEPRECATED: Using `--export-filename` has no impact when backtesting. "
"Please use `--notes` to annotate backtest results and "
"`--backtest-directory` to specify the output directory. "
)
if not config.get("exportdirectory"):
config["exportdirectory"] = config["user_data_dir"] / "backtest_results"
if not config.get("exportfilename"):
config["exportfilename"] = None
config["exportfilename"] = config.get("exportfilename", None)
if config.get("exportfilename"):
# ensure exportfilename is a Path object
config["exportfilename"] = Path(config["exportfilename"])
config["exportdirectory"] = Path(config["exportdirectory"])
if self.args.get("show_sensitive"):
logger.warning(
"Sensitive information will be shown in the upcoming output. "
"Please make sure to never share this output without redacting "
"the information yourself."
)
def _process_optimize_options(self, config: Config) -> None:
# This will override the strategy configuration
self._args_to_config(
@@ -312,6 +312,13 @@ class Configuration:
self._process_datadir_options(config)
if self.args.get("show_sensitive"):
logger.warning(
"Sensitive information will be shown in the upcoming output. "
"Please make sure to never share this output without redacting "
"the information yourself."
)
self._args_to_config(
config,
argname="strategy_list",

File diff suppressed because it is too large Load Diff

View File

@@ -84,7 +84,12 @@ def file_load_json(file: Path):
def is_file_in_dir(file: Path, directory: Path) -> bool:
"""
Helper function to check if file is in directory.
Helper function to check if file is directly within a directory.
:param file: File to check
:param directory: Directory to check against
When used in the API, this parameter cannot be user controlled (outside of the config)
to avoid security issues.
:return: True if file is directly within directory, False otherwise
"""
return file.is_file() and file.parent.samefile(directory)

View File

@@ -37,7 +37,8 @@ class ApiBG:
# Generic background jobs
# TODO: Change this to FtTTLCache
# TODO: Change this to FtTTLCache -> must be more intelligent than FtTTLCache - as we can't
# evict still running jobs.
jobs: dict[str, JobsContainer] = {}
# Pairlist evaluate things
pairlist_running: bool = False

View File

@@ -221,6 +221,9 @@ def test_setup_bt_configuration_with_arguments(mocker, default_conf, caplog) ->
assert "exportfilename" in config
assert isinstance(config["exportfilename"], Path)
assert log_has("Storing backtest results to {} ...".format(config["exportfilename"]), caplog)
assert log_has_re(
"DEPRECATED: Using `--export-filename` has no impact when backtesting.*", caplog
)
assert "fee" in config
assert log_has("Parameter --fee detected, setting fee to: {} ...".format(config["fee"]), caplog)