Add cumulative P&L banner to fund overview for at-a-glance profit/loss.

Expose period delta from equity curve start and surface it in the toolbar and summary cards with green/red cues.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-16 00:19:43 +08:00
parent 83a7465996
commit 717a3d5694
6 changed files with 223 additions and 4 deletions
+32
View File
@@ -74,6 +74,30 @@ def compute_drawdown(values: list[float]) -> dict[str, Any]:
}
def compute_period_delta(series: list[dict]) -> dict[str, Any]:
"""相对曲线起点的资金变动(U 与 %);含出入金影响,口径同权益曲线."""
pts = [
p
for p in (series or [])
if isinstance(p, dict) and isinstance(p.get("total_usdt"), (int, float))
]
if not pts:
return {
"start_usdt": None,
"period_delta_usdt": None,
"period_delta_pct": None,
}
start = round(float(pts[0]["total_usdt"]), 4)
end = round(float(pts[-1]["total_usdt"]), 4)
delta = round(end - start, 4)
pct = round((delta / start) * 100, 2) if start > 0 else None
return {
"start_usdt": start,
"period_delta_usdt": delta,
"period_delta_pct": pct,
}
def _atomic_write(path: Path, data: dict) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
tmp = path.with_suffix(path.suffix + ".tmp")
@@ -343,6 +367,7 @@ def build_fund_overview(
day_delta = round(series[-1]["total_usdt"] - series[-2]["total_usdt"], 4)
elif data_ok and total is not None:
day_delta = round(total - series[-1]["total_usdt"], 4)
period = compute_period_delta(series)
accounts_out.append(
{
@@ -361,6 +386,9 @@ def build_fund_overview(
"series": series,
"drawdown": dd,
"day_delta_usdt": day_delta,
"start_usdt": period["start_usdt"],
"period_delta_usdt": period["period_delta_usdt"],
"period_delta_pct": period["period_delta_pct"],
}
)
if key:
@@ -387,6 +415,7 @@ def build_fund_overview(
total_day_delta = round(
total_series[-1]["total_usdt"] - total_series[-2]["total_usdt"], 4
)
total_period = compute_period_delta(total_series)
return {
"ok": True,
@@ -400,6 +429,9 @@ def build_fund_overview(
"live_known_count": live_known,
"total_usdt": round(live_total, 4) if live_known > 0 else None,
"day_delta_usdt": total_day_delta,
"start_usdt": total_period["start_usdt"],
"period_delta_usdt": total_period["period_delta_usdt"],
"period_delta_pct": total_period["period_delta_pct"],
"series": total_series,
"drawdown": total_dd,
},