Skip to content

Backtest

API endpoints for backtest execution and status.

Provides endpoints for starting backtests and querying their status.

router = APIRouter(prefix='/api/backtest', tags=['backtest']) module-attribute

api_backtest_run(request, background_tasks) async

Start a backtest in the background and return the run ID.

Source code in src/onesecondtrader/dashboard/routers/backtest.py
@router.post("/run")
async def api_backtest_run(
    request: BacktestRequest, background_tasks: BackgroundTasks
) -> dict:
    """Start a backtest in the background and return the run ID."""
    run_id = str(uuid.uuid4())[:8]
    background_tasks.add_task(run_backtest, request, run_id)
    return {"run_id": run_id, "status": "started"}

api_backtest_status(run_id) async

Return the current status of a backtest job.

Source code in src/onesecondtrader/dashboard/routers/backtest.py
@router.get("/status/{run_id}")
async def api_backtest_status(run_id: str) -> dict:
    """Return the current status of a backtest job."""
    status = running_jobs.get(run_id, "not found")
    return {"run_id": run_id, "status": status}