From b6156e00494d111bb53e5ac6b0081a8f3182cf40 Mon Sep 17 00:00:00 2001 From: dekun Date: Thu, 23 Jul 2026 12:44:36 +0800 Subject: [PATCH] Apply account-PnL display pref to dashboard KPI and position tables. Co-authored-by: Cursor --- manual_trading_hub/static/app.js | 5 +++ manual_trading_hub/static/dashboard.js | 57 ++++++++++++++++++-------- manual_trading_hub/static/index.html | 6 +-- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/manual_trading_hub/static/app.js b/manual_trading_hub/static/app.js index cdb0ebb..6edc62a 100644 --- a/manual_trading_hub/static/app.js +++ b/manual_trading_hub/static/app.js @@ -13,6 +13,8 @@ return displayPref("show_account_pnl", true); } + window.hubShowAccountPnlPref = showAccountPnlPref; + function showNavFundsPref() { return displayPref("show_nav_funds", true); } @@ -5187,6 +5189,9 @@ loadSettingsMetaLine(); } if (lastMonitorRows.length) renderMonitorGrid(lastMonitorRows); + if (window.hubDashboardPage && window.hubDashboardPage.refresh) { + window.hubDashboardPage.refresh(); + } if (!pageNavAllowed(currentPage())) { history.replaceState({}, "", "/monitor"); setActiveNav(); diff --git a/manual_trading_hub/static/dashboard.js b/manual_trading_hub/static/dashboard.js index 560cb9b..450742e 100644 --- a/manual_trading_hub/static/dashboard.js +++ b/manual_trading_hub/static/dashboard.js @@ -54,8 +54,16 @@ elStatus.className = "dash-status" + (isErr ? " err" : ""); } + function showAccountPnlPref() { + if (typeof window.hubShowAccountPnlPref === "function") { + return !!window.hubShowAccountPnlPref(); + } + return true; + } + function renderKpi(totals) { if (!elKpi || !totals) return; + const showPnl = showAccountPnlPref(); const closed = Number(totals.total_pnl_u); const floating = Number(totals.float_pnl_u); const funding = totals.total_funding_usdt; @@ -68,16 +76,20 @@ totals.perpetual_open_position_count != null ? Number(totals.perpetual_open_position_count) || 0 : Math.max(0, totalPos - optPos); - const items = [ - kpiItem("交易日", esc(totals.trading_day || "—")), - kpiItem("资金合计", Number.isFinite(funds) ? `${fmt(funds, 2)}U` : "—"), + const items = [kpiItem("交易日", esc(totals.trading_day || "—"))]; + if (showPnl) { + items.push(kpiItem("资金合计", Number.isFinite(funds) ? `${fmt(funds, 2)}U` : "—")); + } + items.push( kpiItem("总持仓数量", `${totalPos}`), kpiItem("期权持仓", `${optPos}`), kpiItem("永续持仓", `${perpPos}`), kpiItem("平仓数量", `${totals.closed_count || 0}`), - kpiItem("平仓盈亏", pnlSigned(closed, 2), pnlClass(closed)), - kpiItem("浮盈亏", pnlSigned(floating, 2), pnlClass(floating)), - ]; + kpiItem("平仓盈亏", pnlSigned(closed, 2), pnlClass(closed)) + ); + if (showPnl) { + items.push(kpiItem("浮盈亏", pnlSigned(floating, 2), pnlClass(floating))); + } elKpi.innerHTML = `
${items.join("")}
`; } @@ -197,6 +209,7 @@ function renderUnifiedPerpTable(rows) { if (!rows.length) return ""; + const showPnl = showAccountPnlPref(); const body = rows .map(({ ac, ln }) => { const source = String((ln && ln.source) || "—"); @@ -213,7 +226,7 @@ ${contracts} ${slTpCell(ln, "sl")} ${slTpCell(ln, "tp")} - ${floatPnlCell(ln)} + ${showPnl ? `${floatPnlCell(ln)}` : ""} `; }) .join(""); @@ -222,7 +235,9 @@
- + ${ + showPnl ? "" : "" + } ${body}
交易所类型合约方向开仓价标记价张数止损止盈浮盈交易所类型合约方向开仓价标记价张数止损止盈浮盈
@@ -291,7 +306,7 @@ return null; } - function renderOptionsLegRow(ac, p) { + function renderOptionsLegRow(ac, p, showPnl) { const optType = (p.opt_type || "").toUpperCase() === "C" ? "Call" @@ -303,21 +318,25 @@ const targetCls = target && target !== "—" ? "dash-target-monitor is-on" : "dash-target-monitor"; const net = optionsNetPnl(p); const roi = optionsRoiPct(p); - return ` + let html = ` ${exchangeLinkCell(ac)} ${sourceTypeCell(source)} ${esc(shortDashInst(p.inst_id))} ${esc(optType)} ${dashOptionsExpiryCd(p.exp_time_ms != null ? p.exp_time_ms : p.exp_time)} ${p.idx_px != null ? fmt(p.idx_px, 0) : "—"} - ${esc(target)} - ${net != null ? pnlSigned(net, 2) : "—"} - ${roi != null ? esc(Number(roi).toFixed(2)) + "%" : "—"} - `; + ${esc(target)}`; + if (showPnl) { + html += `${net != null ? pnlSigned(net, 2) : "—"} + ${roi != null ? esc(Number(roi).toFixed(2)) + "%" : "—"}`; + } + html += ""; + return html; } function renderUnifiedOptionsTable(rows) { if (!rows.length) return ""; + const showPnl = showAccountPnlPref(); // 同所同计划相邻,Call 在前 Put 在后;不额外画分组框 const sorted = rows.slice().sort((a, b) => { const ka = optionsGroupKey(a.ac, a.p); @@ -330,14 +349,16 @@ if (tb === "C") return 1; return ta.localeCompare(tb); }); - const body = sorted.map(({ ac, p }) => renderOptionsLegRow(ac, p)).join(""); + const body = sorted.map(({ ac, p }) => renderOptionsLegRow(ac, p, showPnl)).join(""); return `
- + ${ + showPnl ? "" : "" + } ${body}
交易所类型合约Call/Put到期倒计时指数目标监控净盈亏收益率交易所类型合约Call/Put到期倒计时指数目标监控净盈亏收益率
@@ -539,5 +560,9 @@ inited = false; stopLive(); }, + refresh() { + if (!inited) return; + void fetchDashboardSnapshot({ silent: true, force: true }); + }, }; })(); diff --git a/manual_trading_hub/static/index.html b/manual_trading_hub/static/index.html index 75b168f..139e560 100644 --- a/manual_trading_hub/static/index.html +++ b/manual_trading_hub/static/index.html @@ -1212,7 +1212,7 @@