diff --git a/docs/utils.md b/docs/utils.md index cdf0c31af..dd7a9dfe3 100644 --- a/docs/utils.md +++ b/docs/utils.md @@ -450,6 +450,9 @@ optional arguments: useful if you are redirecting output to a file. --print-json Print best result detailization in JSON format. --no-details Do not print best epoch details. + --export-csv FILE Export to CSV-File. Put + in front of filename to + overwrite. This will disable table print. Example: + --export-csv +hyperopt.csv Common arguments: -v, --verbose Verbose mode (-vv for more, -vvv to get all messages). diff --git a/freqtrade/commands/cli_options.py b/freqtrade/commands/cli_options.py index 77fba8eef..b782c2fb9 100644 --- a/freqtrade/commands/cli_options.py +++ b/freqtrade/commands/cli_options.py @@ -224,7 +224,8 @@ AVAILABLE_CLI_OPTIONS = { "export_csv": Arg( '--export-csv', help='Export to CSV-File. Put + in front of filename to overwrite.' - 'Example: --export-csv +hyperopt.csv', + ' This will disable table print.' + ' Example: --export-csv +hyperopt.csv', metavar='FILE', ), "hyperopt_jobs": Arg( diff --git a/freqtrade/commands/hyperopt_commands.py b/freqtrade/commands/hyperopt_commands.py index f4f119351..efc9aba88 100755 --- a/freqtrade/commands/hyperopt_commands.py +++ b/freqtrade/commands/hyperopt_commands.py @@ -50,17 +50,18 @@ def start_hyperopt_list(args: Dict[str, Any]) -> None: if print_colorized: colorama_init(autoreset=True) - try: - Hyperopt.print_result_table(config, trials, total_epochs, - not filteroptions['only_best'], print_colorized, 0) - except KeyboardInterrupt: - print('User interrupted..') + if not export_csv: + try: + Hyperopt.print_result_table(config, trials, total_epochs, + not filteroptions['only_best'], print_colorized, 0) + except KeyboardInterrupt: + print('User interrupted..') if trials and not no_details: sorted_trials = sorted(trials, key=itemgetter('loss')) results = sorted_trials[0] Hyperopt.print_epoch_details(results, total_epochs, print_json, no_header) - print(export_csv) + if trials and export_csv: overwrite_csv = False if export_csv[0] == '+': diff --git a/tests/commands/test_commands.py b/tests/commands/test_commands.py index 3e1c0a581..58e97fd49 100644 --- a/tests/commands/test_commands.py +++ b/tests/commands/test_commands.py @@ -902,7 +902,21 @@ def test_hyperopt_list(mocker, capsys, hyperopt_results): assert all(x not in captured.out for x in [" 1/12", " 3/12", " 4/12", " 5/12", " 7/12", " 8/12" " 9/12", " 10/12", " 11/12", " 12/12"]) - + args = [ + "hyperopt-list", + "--no-details", + "--export-csv", "+test_file.csv" + ] + pargs = get_args(args) + pargs['config'] = None + start_hyperopt_list(pargs) + captured = capsys.readouterr() + assert all(x in captured.out + for x in ["CSV-File created!"]) + f = Path("test_file.csv") + assert 'Best,1,2,-1.25%,-0.00125625,,-2.51,"3,930.0 m",0.43662' in f.read_text() + assert f.is_file() + f.unlink() def test_hyperopt_show(mocker, capsys, hyperopt_results): mocker.patch(