From 2f95c44777c2f4a6d6be50e23d54922b1a6236f2 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 31 Jul 2023 21:15:33 +0200 Subject: [PATCH] Add "notes" to backtest result output --- freqtrade/data/btanalysis.py | 16 ++++++++++++++++ freqtrade/rpc/api_server/api_schemas.py | 1 + freqtrade/types/backtest_result_type.py | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py index 206588d37..edac74d51 100644 --- a/freqtrade/data/btanalysis.py +++ b/freqtrade/data/btanalysis.py @@ -175,6 +175,21 @@ def _get_backtest_files(dirname: Path) -> List[Path]: return list(reversed(sorted(dirname.glob('backtest-result-*-[0-9][0-9].json')))) +def get_backtest_result(filename: Path) -> List[BacktestHistoryEntryType]: + """ + Get backtest result read from metadata file + """ + return [ + { + 'filename': filename.stem, + 'strategy': s, + 'notes': v.get('notes', ''), + 'run_id': v['run_id'], + 'backtest_start_time': v['backtest_start_time'], + } for s, v in load_backtest_metadata(filename).items() + ] + + def get_backtest_resultlist(dirname: Path) -> List[BacktestHistoryEntryType]: """ Get list of backtest results read from metadata files @@ -184,6 +199,7 @@ def get_backtest_resultlist(dirname: Path) -> List[BacktestHistoryEntryType]: 'filename': filename.stem, 'strategy': s, 'run_id': v['run_id'], + 'notes': v.get('notes', ''), 'backtest_start_time': v['backtest_start_time'], } for filename in _get_backtest_files(dirname) diff --git a/freqtrade/rpc/api_server/api_schemas.py b/freqtrade/rpc/api_server/api_schemas.py index bd405d22b..f96e586bb 100644 --- a/freqtrade/rpc/api_server/api_schemas.py +++ b/freqtrade/rpc/api_server/api_schemas.py @@ -526,6 +526,7 @@ class BacktestHistoryEntry(BaseModel): strategy: str run_id: str backtest_start_time: int + notes: Optional[str] = '' class SysInfo(BaseModel): diff --git a/freqtrade/types/backtest_result_type.py b/freqtrade/types/backtest_result_type.py index bc53097ab..1b66e6b1c 100644 --- a/freqtrade/types/backtest_result_type.py +++ b/freqtrade/types/backtest_result_type.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List +from typing import Any, Dict, List, Optional from typing_extensions import TypedDict @@ -6,6 +6,7 @@ from typing_extensions import TypedDict class BacktestMetadataType(TypedDict): run_id: str backtest_start_time: int + notes: Optional[str] class BacktestResultType(TypedDict):