Skip to content

Runs

API endpoints for run management.

Provides endpoints for listing, deleting, and querying runs and their round-trips.

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

DeleteRunsRequest

Bases: BaseModel

Request model for deleting runs.

Attributes:

Name Type Description
run_ids list[str]

List of run IDs to delete.

Source code in src/onesecondtrader/dashboard/routers/runs.py
class DeleteRunsRequest(BaseModel):
    """
    Request model for deleting runs.

    Attributes:
        run_ids:
            List of run IDs to delete.
    """

    run_ids: list[str]

api_runs() async

Return list of recent runs from the database.

Source code in src/onesecondtrader/dashboard/routers/runs.py
@router.get("/runs")
async def api_runs() -> dict:
    """Return list of recent runs from the database."""
    runs = get_runs()
    return {"runs": runs}

api_delete_runs(request) async

Delete specified runs and their associated data.

Source code in src/onesecondtrader/dashboard/routers/runs.py
@router.delete("/runs")
async def api_delete_runs(request: DeleteRunsRequest) -> dict:
    """Delete specified runs and their associated data."""
    db_path = get_runs_db_path()
    if not os.path.exists(db_path):
        return {"deleted": 0}
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()
    deleted = 0
    for run_id in request.run_ids:
        for table in CHILD_TABLES:
            cursor.execute(f"DELETE FROM {table} WHERE run_id = ?", (run_id,))
        cursor.execute("DELETE FROM runs WHERE run_id = ?", (run_id,))
        deleted += cursor.rowcount
    conn.commit()
    conn.close()
    return {"deleted": deleted}

api_run_roundtrips(run_id) async

Return computed round-trip trades for a run.

Source code in src/onesecondtrader/dashboard/routers/runs.py
@router.get("/runs/{run_id}/roundtrips")
async def api_run_roundtrips(run_id: str) -> dict:
    """Return computed round-trip trades for a run."""
    roundtrips = get_roundtrips(run_id)
    return {"roundtrips": roundtrips}

api_run_chart_image(run_id, symbol, start_ns, end_ns, direction, pnl) async

Return a PNG chart image for a round-trip trade.

Source code in src/onesecondtrader/dashboard/routers/runs.py
@router.get("/runs/{run_id}/chart.png")
async def api_run_chart_image(
    run_id: str,
    symbol: str,
    start_ns: int,
    end_ns: int,
    direction: str,
    pnl: float,
) -> Response:
    """Return a PNG chart image for a round-trip trade."""
    image_bytes = generate_chart_image(run_id, symbol, start_ns, end_ns, direction, pnl)
    return Response(content=image_bytes, media_type="image/png")

api_trade_journey_chart(run_id, symbol=None) async

Return a Trade Journey chart image for round-trip trades in a run, optionally filtered by symbol.

Source code in src/onesecondtrader/dashboard/routers/runs.py
@router.get("/runs/{run_id}/trade-journey.png")
async def api_trade_journey_chart(run_id: str, symbol: str | None = None) -> Response:
    """Return a Trade Journey chart image for round-trip trades in a run, optionally filtered by symbol."""
    roundtrips = get_roundtrips(run_id)
    if symbol:
        roundtrips = [rt for rt in roundtrips if rt["symbol"] == symbol]
    image_bytes = generate_trade_journey_chart(run_id, roundtrips)
    return Response(content=image_bytes, media_type="image/png")

api_pnl_summary_chart(run_id, symbol=None) async

Return a PnL Summary chart image for round-trip trades in a run, optionally filtered by symbol.

Source code in src/onesecondtrader/dashboard/routers/runs.py
@router.get("/runs/{run_id}/pnl-summary.png")
async def api_pnl_summary_chart(run_id: str, symbol: str | None = None) -> Response:
    """Return a PnL Summary chart image for round-trip trades in a run, optionally filtered by symbol."""
    roundtrips = get_roundtrips(run_id)
    if symbol:
        roundtrips = [rt for rt in roundtrips if rt["symbol"] == symbol]
    image_bytes = generate_pnl_summary_chart(roundtrips)
    return Response(content=image_bytes, media_type="image/png")