Fix dashboard TP profit display; add options ROI column.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-20 12:41:32 +08:00
parent 977d62bddf
commit 0f5fe801e2
3 changed files with 92 additions and 19 deletions
+28 -1
View File
@@ -259,6 +259,20 @@
return "solo:" + ex + ":" + String((p && p.inst_id) || Math.random());
}
function optionsRoiPct(p) {
if (!p || typeof p !== "object") return null;
const preview = p.close_preview || {};
if (preview.estimated_pnl_ratio_pct != null && Number.isFinite(Number(preview.estimated_pnl_ratio_pct))) {
return Number(preview.estimated_pnl_ratio_pct);
}
const net = optionsNetPnl(p);
const paid = Number(p.premium_paid);
if (net != null && Number.isFinite(paid) && paid > 0) {
return (net / paid) * 100;
}
return null;
}
function renderOptionsLegRow(ac, p, groupCls) {
const optType =
(p.opt_type || "").toUpperCase() === "C"
@@ -270,6 +284,7 @@
const target = String(p.target_monitor_text || "—");
const targetCls = target && target !== "—" ? "dash-target-monitor is-on" : "dash-target-monitor";
const net = optionsNetPnl(p);
const roi = optionsRoiPct(p);
return `<tr class="${groupCls || ""}">
<td>${exchangeLinkCell(ac)}</td>
<td>${sourceTypeCell(source)}</td>
@@ -279,6 +294,7 @@
<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>`;
}
@@ -322,14 +338,22 @@
groups.forEach((g) => {
if (g.isHedge && g.items.length >= 1) {
let sum = 0;
let paidSum = 0;
let hasSum = false;
let hasPaid = false;
g.items.forEach(({ p }) => {
const n = optionsNetPnl(p);
if (n != null) {
sum += n;
hasSum = true;
}
const paid = Number(p && p.premium_paid);
if (Number.isFinite(paid) && paid > 0) {
paidSum += paid;
hasPaid = true;
}
});
const groupRoi = hasSum && hasPaid && paidSum > 0 ? (sum / paidSum) * 100 : null;
const title =
(g.source && g.source !== "—" ? g.source : "对冲") +
(g.planId ? " #" + g.planId : "") +
@@ -339,6 +363,9 @@
body += `<tr class="dash-opt-group-head">
<td colspan="7"><span class="dash-opt-group-label">${esc(title)}</span></td>
<td class="${hasSum ? pnlClass(sum) : ""}">${hasSum ? pnlSigned(sum, 2) : "—"}</td>
<td class="${groupRoi != null ? pnlClass(groupRoi) : ""}">${
groupRoi != null ? esc(Number(groupRoi).toFixed(2)) + "%" : "—"
}</td>
</tr>`;
g.items.forEach(({ ac, p }, idx) => {
const cls =
@@ -359,7 +386,7 @@
<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>Call/Put</th><th>到期倒计时</th><th>指数</th><th>目标监控</th><th>净盈亏</th><th>收益率</th>
</tr></thead>
<tbody>${body}</tbody>
</table>