Add initial funds to fleet stats and color total PnL.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -79,6 +79,14 @@ def build_stats_summary(db: Any | None = None) -> dict[str, Any]:
|
|||||||
except Exception:
|
except Exception:
|
||||||
latest_funds = 0.0
|
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 {
|
return {
|
||||||
"mode": mode,
|
"mode": mode,
|
||||||
"show_slip": mode == "SIM",
|
"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,
|
"total_slip": total_slip if mode == "SIM" else 0.0,
|
||||||
"close_reasons": reasons,
|
"close_reasons": reasons,
|
||||||
"equity_curve": curve,
|
"equity_curve": curve,
|
||||||
|
"initial_funds": initial_funds,
|
||||||
"latest_funds": latest_funds,
|
"latest_funds": latest_funds,
|
||||||
"max_single_loss": max_single_loss,
|
"max_single_loss": max_single_loss,
|
||||||
"loss_streak": _current_loss_streak(curve),
|
"loss_streak": _current_loss_streak(curve),
|
||||||
|
|||||||
@@ -304,6 +304,7 @@ async def _collect_one_stats(node: dict[str, Any]) -> dict[str, Any]:
|
|||||||
"name": node["name"],
|
"name": node["name"],
|
||||||
"ok": False,
|
"ok": False,
|
||||||
"error": None,
|
"error": None,
|
||||||
|
"initial_funds": None,
|
||||||
"latest_funds": None,
|
"latest_funds": None,
|
||||||
"groups": None,
|
"groups": None,
|
||||||
"fees_perp": 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:
|
if latest_funds is None:
|
||||||
latest_funds = 0.0
|
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(
|
base.update(
|
||||||
{
|
{
|
||||||
"ok": True,
|
"ok": True,
|
||||||
|
"initial_funds": initial_funds,
|
||||||
"latest_funds": latest_funds,
|
"latest_funds": latest_funds,
|
||||||
"groups": data.get("groups"),
|
"groups": data.get("groups"),
|
||||||
"fees_perp": data.get("fees_perp"),
|
"fees_perp": data.get("fees_perp"),
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ type FleetStatsRow = {
|
|||||||
name: string;
|
name: string;
|
||||||
ok: boolean;
|
ok: boolean;
|
||||||
error?: string | null;
|
error?: string | null;
|
||||||
|
initial_funds?: number | null;
|
||||||
latest_funds?: number | null;
|
latest_funds?: number | null;
|
||||||
groups?: number | null;
|
groups?: number | null;
|
||||||
fees_perp?: number | null;
|
fees_perp?: number | null;
|
||||||
@@ -82,6 +83,7 @@ export default function StatsPage() {
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>机器名</th>
|
<th>机器名</th>
|
||||||
|
<th>初始资金</th>
|
||||||
<th>最新资金</th>
|
<th>最新资金</th>
|
||||||
<th>轮次</th>
|
<th>轮次</th>
|
||||||
<th>永续手续费</th>
|
<th>永续手续费</th>
|
||||||
@@ -103,6 +105,9 @@ export default function StatsPage() {
|
|||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
</td>
|
</td>
|
||||||
|
<td className="mono">
|
||||||
|
{row.ok ? fmt(row.initial_funds ?? 0, 2) : "—"}
|
||||||
|
</td>
|
||||||
<td className="mono">
|
<td className="mono">
|
||||||
{row.ok ? fmt(row.latest_funds ?? 0, 2) : "—"}
|
{row.ok ? fmt(row.latest_funds ?? 0, 2) : "—"}
|
||||||
</td>
|
</td>
|
||||||
@@ -139,6 +144,7 @@ export default function StatsPage() {
|
|||||||
({okRows.length}/{fleetStats.length})
|
({okRows.length}/{fleetStats.length})
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
<td className="mono">{fmt(sum("initial_funds"), 2)}</td>
|
||||||
<td className="mono">{fmt(sum("latest_funds"), 2)}</td>
|
<td className="mono">{fmt(sum("latest_funds"), 2)}</td>
|
||||||
<td className="mono">{sum("groups")}</td>
|
<td className="mono">{sum("groups")}</td>
|
||||||
<td className="mono">{fmt(sum("fees_perp"), 4)}</td>
|
<td className="mono">{fmt(sum("fees_perp"), 4)}</td>
|
||||||
|
|||||||
@@ -422,6 +422,18 @@ input {
|
|||||||
color: var(--accent);
|
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 {
|
.btn-sm {
|
||||||
padding: 4px 8px;
|
padding: 4px 8px;
|
||||||
font-size: 0.78rem;
|
font-size: 0.78rem;
|
||||||
|
|||||||
Reference in New Issue
Block a user