Apply account-PnL display pref to dashboard KPI and position tables.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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 = `<div class="dash-kpi-summary">${items.join("")}</div>`;
|
||||
}
|
||||
|
||||
@@ -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 @@
|
||||
<td>${contracts}</td>
|
||||
<td>${slTpCell(ln, "sl")}</td>
|
||||
<td>${slTpCell(ln, "tp")}</td>
|
||||
<td>${floatPnlCell(ln)}</td>
|
||||
${showPnl ? `<td>${floatPnlCell(ln)}</td>` : ""}
|
||||
</tr>`;
|
||||
})
|
||||
.join("");
|
||||
@@ -222,7 +235,9 @@
|
||||
<div class="dash-table-wrap">
|
||||
<table class="dash-table dash-pos-table">
|
||||
<thead><tr>
|
||||
<th>交易所</th><th>类型</th><th>合约</th><th>方向</th><th>开仓价</th><th>标记价</th><th>张数</th><th>止损</th><th>止盈</th><th>浮盈</th>
|
||||
<th>交易所</th><th>类型</th><th>合约</th><th>方向</th><th>开仓价</th><th>标记价</th><th>张数</th><th>止损</th><th>止盈</th>${
|
||||
showPnl ? "<th>浮盈</th>" : ""
|
||||
}
|
||||
</tr></thead>
|
||||
<tbody>${body}</tbody>
|
||||
</table>
|
||||
@@ -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 `<tr>
|
||||
let html = `<tr>
|
||||
<td>${exchangeLinkCell(ac)}</td>
|
||||
<td>${sourceTypeCell(source)}</td>
|
||||
<td title="${esc(p.inst_id || "")}">${esc(shortDashInst(p.inst_id))}</td>
|
||||
<td>${esc(optType)}</td>
|
||||
<td>${dashOptionsExpiryCd(p.exp_time_ms != null ? p.exp_time_ms : p.exp_time)}</td>
|
||||
<td>${p.idx_px != null ? fmt(p.idx_px, 0) : "—"}</td>
|
||||
<td><span class="${targetCls}">${esc(target)}</span></td>
|
||||
<td class="${pnlClass(net)}">${net != null ? pnlSigned(net, 2) : "—"}</td>
|
||||
<td class="${pnlClass(roi)}">${roi != null ? esc(Number(roi).toFixed(2)) + "%" : "—"}</td>
|
||||
</tr>`;
|
||||
<td><span class="${targetCls}">${esc(target)}</span></td>`;
|
||||
if (showPnl) {
|
||||
html += `<td class="${pnlClass(net)}">${net != null ? pnlSigned(net, 2) : "—"}</td>
|
||||
<td class="${pnlClass(roi)}">${roi != null ? esc(Number(roi).toFixed(2)) + "%" : "—"}</td>`;
|
||||
}
|
||||
html += "</tr>";
|
||||
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 `<div class="dash-pos-block dash-options-block">
|
||||
<div class="dash-ac-section-label">期权持仓</div>
|
||||
<div class="dash-table-wrap dash-options-table-wrap">
|
||||
<table class="dash-table dash-options-table">
|
||||
<thead><tr>
|
||||
<th>交易所</th><th>类型</th><th>合约</th><th>Call/Put</th><th>到期倒计时</th><th>指数</th><th>目标监控</th><th>净盈亏</th><th>收益率</th>
|
||||
<th>交易所</th><th>类型</th><th>合约</th><th>Call/Put</th><th>到期倒计时</th><th>指数</th><th>目标监控</th>${
|
||||
showPnl ? "<th>净盈亏</th><th>收益率</th>" : ""
|
||||
}
|
||||
</tr></thead>
|
||||
<tbody>${body}</tbody>
|
||||
</table>
|
||||
@@ -539,5 +560,9 @@
|
||||
inited = false;
|
||||
stopLive();
|
||||
},
|
||||
refresh() {
|
||||
if (!inited) return;
|
||||
void fetchDashboardSnapshot({ silent: true, force: true });
|
||||
},
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1212,7 +1212,7 @@
|
||||
</div>
|
||||
<label class="chk-label settings-display-chk">
|
||||
<input type="checkbox" id="pref-show-account-pnl" checked />
|
||||
监控区显示资金账户、交易账户与浮动盈亏(关闭可隐藏期权盈亏与今日总浮盈)
|
||||
监控区/数据看板显示资金账户、交易账户与浮动盈亏(关闭可隐藏期权盈亏与总浮盈)
|
||||
</label>
|
||||
<label class="chk-label settings-display-chk">
|
||||
<input type="checkbox" id="pref-show-nav-funds" checked />
|
||||
@@ -1506,7 +1506,7 @@
|
||||
<script src="/assets/archive.js?v=20260717-archive-cal-chart"></script>
|
||||
<script src="/assets/quotes.js?v=20260717-quotes-feed"></script>
|
||||
<script src="/assets/funds.js?v=20260717-funds-scroll-fix"></script>
|
||||
<script src="/assets/dashboard.js?v=20260720-dash-sl-tp"></script>
|
||||
<script src="/assets/dashboard.js?v=20260723-hide-pnl"></script>
|
||||
<script src="/assets/strategy.js?v=9"></script>
|
||||
<script src="/assets/amp_stats.js?v=5"></script>
|
||||
<script src="/assets/help.js?v=1"></script>
|
||||
@@ -1516,6 +1516,6 @@
|
||||
<script src="/assets/options_expiry_countdown.js?v=1"></script>
|
||||
<script src="/assets/options_position_cards.js?v=3"></script>
|
||||
<script src="/assets/backup.js?v=1"></script>
|
||||
<script src="/assets/app.js?v=20260723-hide-pnl"></script>
|
||||
<script src="/assets/app.js?v=20260723-dash-hide-pnl"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user