Show strategy stats in control monitor detail modal.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Annotated
|
||||
from typing import Annotated, Any
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
@@ -12,12 +12,12 @@ from .auth import require_user
|
||||
router = APIRouter(prefix="/api/stats", tags=["stats"])
|
||||
|
||||
|
||||
@router.get("/summary")
|
||||
async def stats_summary(_user: Annotated[str, Depends(require_user)]) -> dict:
|
||||
db = get_db()
|
||||
def build_stats_summary(db: Any | None = None) -> dict[str, Any]:
|
||||
"""已平仓组汇总(策略页统计 / 中控 Fleet 共用)。"""
|
||||
database = db or get_db()
|
||||
s = get_settings()
|
||||
mode = "LIVE" if not s.is_sim else "SIM"
|
||||
rows = db.fetchall("SELECT * FROM groups WHERE status='closed'")
|
||||
rows = database.fetchall("SELECT * FROM groups WHERE status='closed'")
|
||||
n = len(rows)
|
||||
wins = sum(1 for r in rows if float(r["realized_pnl"] or 0) > 0)
|
||||
total_pnl = sum(float(r["realized_pnl"] or 0) for r in rows)
|
||||
@@ -26,7 +26,7 @@ async def stats_summary(_user: Annotated[str, Depends(require_user)]) -> dict:
|
||||
fees_option = 0.0
|
||||
total_slip = 0.0
|
||||
for r in rows:
|
||||
fills = db.fetchall(
|
||||
fills = database.fetchall(
|
||||
"SELECT * FROM fills WHERE group_id=? ORDER BY id ASC",
|
||||
(r["group_id"],),
|
||||
)
|
||||
@@ -65,3 +65,8 @@ async def stats_summary(_user: Annotated[str, Depends(require_user)]) -> dict:
|
||||
"close_reasons": reasons,
|
||||
"equity_curve": curve,
|
||||
}
|
||||
|
||||
|
||||
@router.get("/summary")
|
||||
async def stats_summary(_user: Annotated[str, Depends(require_user)]) -> dict:
|
||||
return build_stats_summary()
|
||||
|
||||
Reference in New Issue
Block a user