fix: backtest submission shows no results — 4 bugs fixed

- ID mismatch: API generated a throwaway UUID while BacktestReplay
  generated its own internally. Frontend polled with wrong ID and
  never found the DB row. Now pre-generate ID in endpoint and pass
  it to BacktestReplay.
- Field name: API returned 'backtest_id' but frontend read 'data.id'.
  Unified to 'id' everywhere.
- No polling: useBacktestResult fired once and never refreshed.
  Added refetchInterval that polls every 2s while status is running.
- Response shape: GET endpoint nested results under 'result' object
  but frontend expected flat fields. Flattened response to match
  BacktestResult type.
- Added running/failed/completed status indicators in BacktestPanel.
This commit is contained in:
Celes Renata
2026-04-17 00:31:17 +00:00
parent f11aa0a1ee
commit f2d8744a4f
5 changed files with 74 additions and 51 deletions
+4 -2
View File
@@ -39,16 +39,18 @@ class BacktestReplay:
self.pool = pool
self._perf = PerformanceComputer()
async def run(self, config: BacktestConfig) -> BacktestResult:
async def run(self, config: BacktestConfig, backtest_id: str | None = None) -> BacktestResult:
"""Execute a full backtest replay.
Args:
config: Backtest configuration (date range, capital, risk tier).
backtest_id: Optional pre-generated ID. If not provided, one is generated.
Returns:
BacktestResult with metrics, trade log, and equity curve.
"""
backtest_id = str(uuid.uuid4())
if backtest_id is None:
backtest_id = str(uuid.uuid4())
try:
# Fetch historical recommendations