e51f357b48
Co-authored-by: Cursor <cursoragent@cursor.com>
31 lines
977 B
Python
31 lines
977 B
Python
from __future__ import annotations
|
|
|
|
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
|
|
from ..market import get_gateway
|
|
from .auth import require_user
|
|
|
|
router = APIRouter(prefix="/api/market", tags=["market"])
|
|
|
|
|
|
@router.get("/snapshot")
|
|
async def market_snapshot(_user: Annotated[str, Depends(require_user)]) -> dict:
|
|
gw = get_gateway()
|
|
snap = gw.snapshot_dict()
|
|
if snap.get("pair") is None:
|
|
raise HTTPException(status_code=503, detail="market not aligned yet")
|
|
return snap
|
|
|
|
|
|
@router.post("/realign")
|
|
async def market_realign(_user: Annotated[str, Depends(require_user)]) -> dict:
|
|
"""手动重对齐次日到期 ATM 合约(运维/调试用)。"""
|
|
gw = get_gateway()
|
|
try:
|
|
pair = await gw.realign_async()
|
|
except Exception as e:
|
|
raise HTTPException(status_code=502, detail=str(e)) from e
|
|
return {"ok": True, "pair": pair.to_dict() if pair else None, "snapshot": gw.snapshot_dict()}
|