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)):
|
def api_backtest_history_result(filename: str, strategy: str, config=Depends(get_config)):
|
||||||
# Get backtest result history, read from metadata files
|
# Get backtest result history, read from metadata files
|
||||||
bt_results_base: Path = config["user_data_dir"] / "backtest_results"
|
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] = {
|
results: dict[str, Any] = {
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"strategy": {},
|
"strategy": {},
|
||||||
"strategy_comparison": [],
|
"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)
|
load_and_merge_backtest_result(strategy, fn, results)
|
||||||
return {
|
return {
|
||||||
"status": "ended",
|
"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)):
|
def api_delete_backtest_history_entry(file: str, config=Depends(get_config)):
|
||||||
# Get backtest result history, read from metadata files
|
# Get backtest result history, read from metadata files
|
||||||
bt_results_base: Path = config["user_data_dir"] / "backtest_results"
|
bt_results_base: Path = config["user_data_dir"] / "backtest_results"
|
||||||
file_abs = (bt_results_base / file).with_suffix(".json")
|
for ext in [".zip", ".json"]:
|
||||||
# Ensure file is in backtest_results directory
|
file_abs = (bt_results_base / file).with_suffix(ext)
|
||||||
if not is_file_in_dir(file_abs, bt_results_base):
|
# 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.")
|
raise HTTPException(status_code=404, detail="File not found.")
|
||||||
|
|
||||||
delete_backtest_result(file_abs)
|
delete_backtest_result(file_abs)
|
||||||
@@ -320,10 +326,14 @@ def api_update_backtest_history_entry(
|
|||||||
):
|
):
|
||||||
# Get backtest result history, read from metadata files
|
# Get backtest result history, read from metadata files
|
||||||
bt_results_base: Path = config["user_data_dir"] / "backtest_results"
|
bt_results_base: Path = config["user_data_dir"] / "backtest_results"
|
||||||
file_abs = (bt_results_base / file).with_suffix(".json")
|
for ext in [".zip", ".json"]:
|
||||||
# Ensure file is in backtest_results directory
|
file_abs = (bt_results_base / file).with_suffix(ext)
|
||||||
if not is_file_in_dir(file_abs, bt_results_base):
|
# 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.")
|
raise HTTPException(status_code=404, detail="File not found.")
|
||||||
|
|
||||||
content = {"notes": body.notes}
|
content = {"notes": body.notes}
|
||||||
try:
|
try:
|
||||||
update_backtest_metadata(file_abs, body.strategy, content)
|
update_backtest_metadata(file_abs, body.strategy, content)
|
||||||
|
|||||||
Reference in New Issue
Block a user