Fix backtest detail API — check historical/ subdirectory first

Bug: /api/backtest/{name} only looked in backtests/results/,
but all historical backtests are saved in backtests/results/historical/.
Fix: check HISTORICAL_DIR first, then fall back to BACKTEST_DIR.
This fixes SPX backtest detail showing zero prices/fees.
This commit is contained in:
ramseshk
2026-08-06 07:44:07 +00:00
parent 6fcf5e7c7d
commit 392bde44a0
+5 -2
View File
@@ -236,8 +236,11 @@ async def list_backtests():
@app.get("/api/backtest/{name}")
async def get_backtest(name: str):
"""Get full backtest result data."""
fpath = os.path.join(BACKTEST_DIR, f"{name}.json")
"""Get full backtest result data — checks historical dir first."""
# Try historical subdirectory first (where dashboard saves backtests)
fpath = os.path.join(HISTORICAL_DIR, f"{name}.json")
if not os.path.exists(fpath):
fpath = os.path.join(BACKTEST_DIR, f"{name}.json")
if os.path.exists(fpath):
with open(fpath) as f:
return JSONResponse(json.load(f))