Use all-time closed groups for funds bar trade stats.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+10
-12
@@ -66,16 +66,14 @@ async def funds_summary(_user: Annotated[str, Depends(require_user)]) -> dict[st
|
||||
exchange = str(st.get("exchange") or s.exchange or "okx").upper()
|
||||
trading_day = datetime.now(SH).strftime("%Y-%m-%d")
|
||||
|
||||
# 顶栏「总交易 / 胜率 / 盈亏比」与交易日同一口径:上海自然日开仓组 G-YYYYMMDD-*
|
||||
day_prefix = trading_day.replace("-", "")
|
||||
day_groups = db.fetchall(
|
||||
"SELECT realized_pnl FROM groups WHERE group_id LIKE ? AND status='closed'",
|
||||
(f"G-{day_prefix}-%",),
|
||||
# 顶栏「总交易 / 胜率 / 盈亏比」统一历史累计(全部已平组)
|
||||
closed = db.fetchall(
|
||||
"SELECT realized_pnl FROM groups WHERE status='closed'"
|
||||
)
|
||||
day_pnls = [float(r["realized_pnl"] or 0) for r in day_groups]
|
||||
day_n = len(day_pnls)
|
||||
day_wins = sum(1 for x in day_pnls if x > 0)
|
||||
day_win_rate = (day_wins / day_n) if day_n else 0.0
|
||||
pnls = [float(r["realized_pnl"] or 0) for r in closed]
|
||||
n = len(pnls)
|
||||
wins = sum(1 for x in pnls if x > 0)
|
||||
win_rate = (wins / n) if n else 0.0
|
||||
|
||||
pos = st.get("position") or {}
|
||||
realtime = None
|
||||
@@ -139,9 +137,9 @@ async def funds_summary(_user: Annotated[str, Depends(require_user)]) -> dict[st
|
||||
"mode": mode,
|
||||
"exchange": exchange,
|
||||
"trading_day": trading_day,
|
||||
"total_trades": day_n,
|
||||
"win_rate": day_win_rate,
|
||||
"profit_loss_ratio": _pl_ratio(day_pnls),
|
||||
"total_trades": n,
|
||||
"win_rate": win_rate,
|
||||
"profit_loss_ratio": _pl_ratio(pnls),
|
||||
"total_funds": total,
|
||||
"funding_usdt": funding_usdt,
|
||||
"trading_usdt": trading_usdt,
|
||||
|
||||
Reference in New Issue
Block a user