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);
|
return displayPref("show_account_pnl", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.hubShowAccountPnlPref = showAccountPnlPref;
|
||||||
|
|
||||||
function showNavFundsPref() {
|
function showNavFundsPref() {
|
||||||
return displayPref("show_nav_funds", true);
|
return displayPref("show_nav_funds", true);
|
||||||
}
|
}
|
||||||
@@ -5187,6 +5189,9 @@
|
|||||||
loadSettingsMetaLine();
|
loadSettingsMetaLine();
|
||||||
}
|
}
|
||||||
if (lastMonitorRows.length) renderMonitorGrid(lastMonitorRows);
|
if (lastMonitorRows.length) renderMonitorGrid(lastMonitorRows);
|
||||||
|
if (window.hubDashboardPage && window.hubDashboardPage.refresh) {
|
||||||
|
window.hubDashboardPage.refresh();
|
||||||
|
}
|
||||||
if (!pageNavAllowed(currentPage())) {
|
if (!pageNavAllowed(currentPage())) {
|
||||||
history.replaceState({}, "", "/monitor");
|
history.replaceState({}, "", "/monitor");
|
||||||
setActiveNav();
|
setActiveNav();
|
||||||
|
|||||||
@@ -54,8 +54,16 @@
|
|||||||
elStatus.className = "dash-status" + (isErr ? " err" : "");
|
elStatus.className = "dash-status" + (isErr ? " err" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showAccountPnlPref() {
|
||||||
|
if (typeof window.hubShowAccountPnlPref === "function") {
|
||||||
|
return !!window.hubShowAccountPnlPref();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function renderKpi(totals) {
|
function renderKpi(totals) {
|
||||||
if (!elKpi || !totals) return;
|
if (!elKpi || !totals) return;
|
||||||
|
const showPnl = showAccountPnlPref();
|
||||||
const closed = Number(totals.total_pnl_u);
|
const closed = Number(totals.total_pnl_u);
|
||||||
const floating = Number(totals.float_pnl_u);
|
const floating = Number(totals.float_pnl_u);
|
||||||
const funding = totals.total_funding_usdt;
|
const funding = totals.total_funding_usdt;
|
||||||
@@ -68,16 +76,20 @@
|
|||||||
totals.perpetual_open_position_count != null
|
totals.perpetual_open_position_count != null
|
||||||
? Number(totals.perpetual_open_position_count) || 0
|
? Number(totals.perpetual_open_position_count) || 0
|
||||||
: Math.max(0, totalPos - optPos);
|
: Math.max(0, totalPos - optPos);
|
||||||
const items = [
|
const items = [kpiItem("交易日", esc(totals.trading_day || "—"))];
|
||||||
kpiItem("交易日", esc(totals.trading_day || "—")),
|
if (showPnl) {
|
||||||
kpiItem("资金合计", Number.isFinite(funds) ? `${fmt(funds, 2)}U` : "—"),
|
items.push(kpiItem("资金合计", Number.isFinite(funds) ? `${fmt(funds, 2)}U` : "—"));
|
||||||
|
}
|
||||||
|
items.push(
|
||||||
kpiItem("总持仓数量", `${totalPos}`),
|
kpiItem("总持仓数量", `${totalPos}`),
|
||||||
kpiItem("期权持仓", `${optPos}`),
|
kpiItem("期权持仓", `${optPos}`),
|
||||||
kpiItem("永续持仓", `${perpPos}`),
|
kpiItem("永续持仓", `${perpPos}`),
|
||||||
kpiItem("平仓数量", `${totals.closed_count || 0}`),
|
kpiItem("平仓数量", `${totals.closed_count || 0}`),
|
||||||
kpiItem("平仓盈亏", pnlSigned(closed, 2), pnlClass(closed)),
|
kpiItem("平仓盈亏", pnlSigned(closed, 2), pnlClass(closed))
|
||||||
kpiItem("浮盈亏", pnlSigned(floating, 2), pnlClass(floating)),
|
);
|
||||||
];
|
if (showPnl) {
|
||||||
|
items.push(kpiItem("浮盈亏", pnlSigned(floating, 2), pnlClass(floating)));
|
||||||
|
}
|
||||||
elKpi.innerHTML = `<div class="dash-kpi-summary">${items.join("")}</div>`;
|
elKpi.innerHTML = `<div class="dash-kpi-summary">${items.join("")}</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,6 +209,7 @@
|
|||||||
|
|
||||||
function renderUnifiedPerpTable(rows) {
|
function renderUnifiedPerpTable(rows) {
|
||||||
if (!rows.length) return "";
|
if (!rows.length) return "";
|
||||||
|
const showPnl = showAccountPnlPref();
|
||||||
const body = rows
|
const body = rows
|
||||||
.map(({ ac, ln }) => {
|
.map(({ ac, ln }) => {
|
||||||
const source = String((ln && ln.source) || "—");
|
const source = String((ln && ln.source) || "—");
|
||||||
@@ -213,7 +226,7 @@
|
|||||||
<td>${contracts}</td>
|
<td>${contracts}</td>
|
||||||
<td>${slTpCell(ln, "sl")}</td>
|
<td>${slTpCell(ln, "sl")}</td>
|
||||||
<td>${slTpCell(ln, "tp")}</td>
|
<td>${slTpCell(ln, "tp")}</td>
|
||||||
<td>${floatPnlCell(ln)}</td>
|
${showPnl ? `<td>${floatPnlCell(ln)}</td>` : ""}
|
||||||
</tr>`;
|
</tr>`;
|
||||||
})
|
})
|
||||||
.join("");
|
.join("");
|
||||||
@@ -222,7 +235,9 @@
|
|||||||
<div class="dash-table-wrap">
|
<div class="dash-table-wrap">
|
||||||
<table class="dash-table dash-pos-table">
|
<table class="dash-table dash-pos-table">
|
||||||
<thead><tr>
|
<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>
|
</tr></thead>
|
||||||
<tbody>${body}</tbody>
|
<tbody>${body}</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -291,7 +306,7 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderOptionsLegRow(ac, p) {
|
function renderOptionsLegRow(ac, p, showPnl) {
|
||||||
const optType =
|
const optType =
|
||||||
(p.opt_type || "").toUpperCase() === "C"
|
(p.opt_type || "").toUpperCase() === "C"
|
||||||
? "Call"
|
? "Call"
|
||||||
@@ -303,21 +318,25 @@
|
|||||||
const targetCls = target && target !== "—" ? "dash-target-monitor is-on" : "dash-target-monitor";
|
const targetCls = target && target !== "—" ? "dash-target-monitor is-on" : "dash-target-monitor";
|
||||||
const net = optionsNetPnl(p);
|
const net = optionsNetPnl(p);
|
||||||
const roi = optionsRoiPct(p);
|
const roi = optionsRoiPct(p);
|
||||||
return `<tr>
|
let html = `<tr>
|
||||||
<td>${exchangeLinkCell(ac)}</td>
|
<td>${exchangeLinkCell(ac)}</td>
|
||||||
<td>${sourceTypeCell(source)}</td>
|
<td>${sourceTypeCell(source)}</td>
|
||||||
<td title="${esc(p.inst_id || "")}">${esc(shortDashInst(p.inst_id))}</td>
|
<td title="${esc(p.inst_id || "")}">${esc(shortDashInst(p.inst_id))}</td>
|
||||||
<td>${esc(optType)}</td>
|
<td>${esc(optType)}</td>
|
||||||
<td>${dashOptionsExpiryCd(p.exp_time_ms != null ? p.exp_time_ms : p.exp_time)}</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>${p.idx_px != null ? fmt(p.idx_px, 0) : "—"}</td>
|
||||||
<td><span class="${targetCls}">${esc(target)}</span></td>
|
<td><span class="${targetCls}">${esc(target)}</span></td>`;
|
||||||
<td class="${pnlClass(net)}">${net != null ? pnlSigned(net, 2) : "—"}</td>
|
if (showPnl) {
|
||||||
<td class="${pnlClass(roi)}">${roi != null ? esc(Number(roi).toFixed(2)) + "%" : "—"}</td>
|
html += `<td class="${pnlClass(net)}">${net != null ? pnlSigned(net, 2) : "—"}</td>
|
||||||
</tr>`;
|
<td class="${pnlClass(roi)}">${roi != null ? esc(Number(roi).toFixed(2)) + "%" : "—"}</td>`;
|
||||||
|
}
|
||||||
|
html += "</tr>";
|
||||||
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderUnifiedOptionsTable(rows) {
|
function renderUnifiedOptionsTable(rows) {
|
||||||
if (!rows.length) return "";
|
if (!rows.length) return "";
|
||||||
|
const showPnl = showAccountPnlPref();
|
||||||
// 同所同计划相邻,Call 在前 Put 在后;不额外画分组框
|
// 同所同计划相邻,Call 在前 Put 在后;不额外画分组框
|
||||||
const sorted = rows.slice().sort((a, b) => {
|
const sorted = rows.slice().sort((a, b) => {
|
||||||
const ka = optionsGroupKey(a.ac, a.p);
|
const ka = optionsGroupKey(a.ac, a.p);
|
||||||
@@ -330,14 +349,16 @@
|
|||||||
if (tb === "C") return 1;
|
if (tb === "C") return 1;
|
||||||
return ta.localeCompare(tb);
|
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">
|
return `<div class="dash-pos-block dash-options-block">
|
||||||
<div class="dash-ac-section-label">期权持仓</div>
|
<div class="dash-ac-section-label">期权持仓</div>
|
||||||
<div class="dash-table-wrap dash-options-table-wrap">
|
<div class="dash-table-wrap dash-options-table-wrap">
|
||||||
<table class="dash-table dash-options-table">
|
<table class="dash-table dash-options-table">
|
||||||
<thead><tr>
|
<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>
|
</tr></thead>
|
||||||
<tbody>${body}</tbody>
|
<tbody>${body}</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -539,5 +560,9 @@
|
|||||||
inited = false;
|
inited = false;
|
||||||
stopLive();
|
stopLive();
|
||||||
},
|
},
|
||||||
|
refresh() {
|
||||||
|
if (!inited) return;
|
||||||
|
void fetchDashboardSnapshot({ silent: true, force: true });
|
||||||
|
},
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -1212,7 +1212,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<label class="chk-label settings-display-chk">
|
<label class="chk-label settings-display-chk">
|
||||||
<input type="checkbox" id="pref-show-account-pnl" checked />
|
<input type="checkbox" id="pref-show-account-pnl" checked />
|
||||||
监控区显示资金账户、交易账户与浮动盈亏(关闭可隐藏期权盈亏与今日总浮盈)
|
监控区/数据看板显示资金账户、交易账户与浮动盈亏(关闭可隐藏期权盈亏与总浮盈)
|
||||||
</label>
|
</label>
|
||||||
<label class="chk-label settings-display-chk">
|
<label class="chk-label settings-display-chk">
|
||||||
<input type="checkbox" id="pref-show-nav-funds" checked />
|
<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/archive.js?v=20260717-archive-cal-chart"></script>
|
||||||
<script src="/assets/quotes.js?v=20260717-quotes-feed"></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/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/strategy.js?v=9"></script>
|
||||||
<script src="/assets/amp_stats.js?v=5"></script>
|
<script src="/assets/amp_stats.js?v=5"></script>
|
||||||
<script src="/assets/help.js?v=1"></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_expiry_countdown.js?v=1"></script>
|
||||||
<script src="/assets/options_position_cards.js?v=3"></script>
|
<script src="/assets/options_position_cards.js?v=3"></script>
|
||||||
<script src="/assets/backup.js?v=1"></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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user