Add initial funds to fleet stats and color total PnL.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-02 12:51:47 +08:00
parent 51aef1c2fb
commit 60b3743e8d
4 changed files with 37 additions and 0 deletions
+9
View File
@@ -79,6 +79,14 @@ def build_stats_summary(db: Any | None = None) -> dict[str, Any]:
except Exception:
latest_funds = 0.0
try:
initial_funds = float(
database.get_setting("initial_equity", str(s.initial_equity))
or s.initial_equity
)
except Exception:
initial_funds = float(s.initial_equity)
return {
"mode": mode,
"show_slip": mode == "SIM",
@@ -92,6 +100,7 @@ def build_stats_summary(db: Any | None = None) -> dict[str, Any]:
"total_slip": total_slip if mode == "SIM" else 0.0,
"close_reasons": reasons,
"equity_curve": curve,
"initial_funds": initial_funds,
"latest_funds": latest_funds,
"max_single_loss": max_single_loss,
"loss_streak": _current_loss_streak(curve),
+10
View File
@@ -304,6 +304,7 @@ async def _collect_one_stats(node: dict[str, Any]) -> dict[str, Any]:
"name": node["name"],
"ok": False,
"error": None,
"initial_funds": None,
"latest_funds": None,
"groups": None,
"fees_perp": None,
@@ -345,9 +346,18 @@ async def _collect_one_stats(node: dict[str, Any]) -> dict[str, Any]:
if latest_funds is None:
latest_funds = 0.0
initial_funds = data.get("initial_funds")
if initial_funds is None:
# 旧版策略机:用最新资金 − 已实现盈亏近似初始资金
try:
initial_funds = float(latest_funds) - float(data.get("total_pnl") or 0)
except Exception:
initial_funds = None
base.update(
{
"ok": True,
"initial_funds": initial_funds,
"latest_funds": latest_funds,
"groups": data.get("groups"),
"fees_perp": data.get("fees_perp"),
+6
View File
@@ -6,6 +6,7 @@ type FleetStatsRow = {
name: string;
ok: boolean;
error?: string | null;
initial_funds?: number | null;
latest_funds?: number | null;
groups?: number | null;
fees_perp?: number | null;
@@ -82,6 +83,7 @@ export default function StatsPage() {
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
@@ -103,6 +105,9 @@ export default function StatsPage() {
</div>
) : null}
</td>
<td className="mono">
{row.ok ? fmt(row.initial_funds ?? 0, 2) : "—"}
</td>
<td className="mono">
{row.ok ? fmt(row.latest_funds ?? 0, 2) : "—"}
</td>
@@ -139,6 +144,7 @@ export default function StatsPage() {
({okRows.length}/{fleetStats.length})
</span>
</td>
<td className="mono">{fmt(sum("initial_funds"), 2)}</td>
<td className="mono">{fmt(sum("latest_funds"), 2)}</td>
<td className="mono">{sum("groups")}</td>
<td className="mono">{fmt(sum("fees_perp"), 4)}</td>
+12
View File
@@ -422,6 +422,18 @@ input {
color: var(--accent);
}
.stats-table tfoot .stats-total-row td.pnl-pos {
color: var(--pnl-pos);
}
.stats-table tfoot .stats-total-row td.pnl-neg {
color: var(--pnl-neg);
}
.stats-table tfoot .stats-total-row td.pnl-flat {
color: var(--text);
}
.btn-sm {
padding: 4px 8px;
font-size: 0.78rem;