mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-01-21 06:20:24 +00:00
feat: load backtest data via API from both zip and json
This commit is contained in:
@@ -273,15 +273,18 @@ def api_backtest_history(config=Depends(get_config)):
|
||||
def api_backtest_history_result(filename: str, strategy: str, config=Depends(get_config)):
|
||||
# Get backtest result history, read from metadata files
|
||||
bt_results_base: Path = config["user_data_dir"] / "backtest_results"
|
||||
fn = (bt_results_base / filename).with_suffix(".json")
|
||||
for ext in [".zip", ".json"]:
|
||||
fn = (bt_results_base / filename).with_suffix(ext)
|
||||
if is_file_in_dir(fn, bt_results_base):
|
||||
break
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="File not found.")
|
||||
|
||||
results: dict[str, Any] = {
|
||||
"metadata": {},
|
||||
"strategy": {},
|
||||
"strategy_comparison": [],
|
||||
}
|
||||
if not is_file_in_dir(fn, bt_results_base):
|
||||
raise HTTPException(status_code=404, detail="File not found.")
|
||||
load_and_merge_backtest_result(strategy, fn, results)
|
||||
return {
|
||||
"status": "ended",
|
||||
@@ -301,9 +304,12 @@ def api_backtest_history_result(filename: str, strategy: str, config=Depends(get
|
||||
def api_delete_backtest_history_entry(file: str, config=Depends(get_config)):
|
||||
# Get backtest result history, read from metadata files
|
||||
bt_results_base: Path = config["user_data_dir"] / "backtest_results"
|
||||
file_abs = (bt_results_base / file).with_suffix(".json")
|
||||
# Ensure file is in backtest_results directory
|
||||
if not is_file_in_dir(file_abs, bt_results_base):
|
||||
for ext in [".zip", ".json"]:
|
||||
file_abs = (bt_results_base / file).with_suffix(ext)
|
||||
# Ensure file is in backtest_results directory
|
||||
if is_file_in_dir(file_abs, bt_results_base):
|
||||
break
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="File not found.")
|
||||
|
||||
delete_backtest_result(file_abs)
|
||||
@@ -320,10 +326,14 @@ def api_update_backtest_history_entry(
|
||||
):
|
||||
# Get backtest result history, read from metadata files
|
||||
bt_results_base: Path = config["user_data_dir"] / "backtest_results"
|
||||
file_abs = (bt_results_base / file).with_suffix(".json")
|
||||
# Ensure file is in backtest_results directory
|
||||
if not is_file_in_dir(file_abs, bt_results_base):
|
||||
for ext in [".zip", ".json"]:
|
||||
file_abs = (bt_results_base / file).with_suffix(ext)
|
||||
# Ensure file is in backtest_results directory
|
||||
if is_file_in_dir(file_abs, bt_results_base):
|
||||
break
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="File not found.")
|
||||
|
||||
content = {"notes": body.notes}
|
||||
try:
|
||||
update_backtest_metadata(file_abs, body.strategy, content)
|
||||
|
||||
Reference in New Issue
Block a user