51b8bb8f8a
Co-authored-by: Cursor <cursoragent@cursor.com>
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Annotated, Any
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
|
|
from ..models.db import get_db
|
|
from .auth import require_user
|
|
|
|
router = APIRouter(prefix="/api/trades", tags=["trades"])
|
|
|
|
|
|
def _row(r: Any) -> dict:
|
|
return dict(r)
|
|
|
|
|
|
@router.get("/groups")
|
|
async def list_groups(_user: Annotated[str, Depends(require_user)]) -> dict:
|
|
rows = get_db().fetchall(
|
|
"SELECT * FROM groups ORDER BY open_at_ms DESC LIMIT 200"
|
|
)
|
|
return {"groups": [_row(x) for x in rows]}
|
|
|
|
|
|
@router.get("/groups/{group_id}")
|
|
async def group_detail(group_id: str, _user: Annotated[str, Depends(require_user)]) -> dict:
|
|
db = get_db()
|
|
g = db.fetchone("SELECT * FROM groups WHERE group_id=?", (group_id,))
|
|
if g is None:
|
|
raise HTTPException(status_code=404, detail="group not found")
|
|
fills = db.fetchall(
|
|
"SELECT * FROM fills WHERE group_id=? ORDER BY id ASC", (group_id,)
|
|
)
|
|
return {"group": _row(g), "fills": [_row(x) for x in fills]}
|