币本位期权数据统计按指数折算为U,不再误标USDC导致0.00

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-21 06:17:55 +08:00
parent 9421ff7360
commit 893a2cc115
5 changed files with 149 additions and 75 deletions
+22 -11
View File
@@ -2367,7 +2367,14 @@
}
}
function paintPnlStat(el, value) {
function statsPnlUnit(d) {
const u = String((d && d.pnl_unit) || "").trim().toUpperCase();
if (u === "U" || u === "USDT") return "U";
if (u === "ETH" || u === "BTC") return u;
return "USDC";
}
function paintPnlStat(el, value, unit) {
if (!el) return;
if (value == null || value === "" || Number.isNaN(Number(value))) {
el.textContent = "—";
@@ -2375,7 +2382,9 @@
return;
}
const n = Number(value);
el.textContent = (n > 0 ? "+" : "") + fmt(n, 2) + " USDC";
const label = unit || "USDC";
const decimals = label === "ETH" || label === "BTC" ? 6 : 2;
el.textContent = (n > 0 ? "+" : "") + fmt(n, decimals) + " " + label;
el.classList.toggle("pos-pnl-profit", n > 0);
el.classList.toggle("pos-pnl-loss", n < 0);
}
@@ -2405,9 +2414,10 @@
paintStatsCharts(null);
return;
}
paintPnlStat(totalPnlEl, d.total_pnl);
paintPnlStat(netRealizedEl, d.net_realized_pnl);
paintPnlStat(openFloatEl, d.open_float_pnl);
const unit = statsPnlUnit(d);
paintPnlStat(totalPnlEl, d.total_pnl, unit);
paintPnlStat(netRealizedEl, d.net_realized_pnl, unit);
paintPnlStat(openFloatEl, d.open_float_pnl, unit);
if (winEl) winEl.textContent = d.total_closed ? d.win_rate + "%" : "0%";
if (plrEl) {
plrEl.textContent = d.profit_loss_ratio != null ? String(d.profit_loss_ratio) : "—";
@@ -2415,11 +2425,11 @@
if (closedEl) closedEl.textContent = String(d.total_closed || 0);
if (profitEl) {
profitEl.textContent = d.avg_win != null && d.avg_win > 0
? fmt(d.avg_win, 2) + " USDC" : (d.win_count ? "0 USDC" : "—");
? fmt(d.avg_win, 2) + " " + unit : (d.win_count ? "0 " + unit : "—");
}
if (lossEl) {
lossEl.textContent = d.avg_loss != null && d.avg_loss > 0
? fmt(d.avg_loss, 2) + " USDC" : (d.loss_count ? "0 USDC" : "—");
? fmt(d.avg_loss, 2) + " " + unit : (d.loss_count ? "0 " + unit : "—");
}
if (avgHoldEl) avgHoldEl.textContent = fmtDuration(d.avg_hold_sec);
if (winHoldEl) winHoldEl.textContent = fmtDuration(d.avg_win_hold_sec);
@@ -2484,17 +2494,18 @@
const profit = Math.max(0, Number(d.avg_win) || 0);
const loss = Math.max(0, Number(d.avg_loss) || 0);
const unit = statsPnlUnit(d);
const pnlTotal = profit + loss;
if (pnlTotal > 0) {
setBarFill(profitBar, (profit / pnlTotal) * 100);
setBarFill(lossBar, (loss / pnlTotal) * 100);
if (profitBarLabel) profitBarLabel.textContent = fmt(profit, 2) + " USDC";
if (lossBarLabel) lossBarLabel.textContent = fmt(loss, 2) + " USDC";
if (profitBarLabel) profitBarLabel.textContent = fmt(profit, 2) + " " + unit;
if (lossBarLabel) lossBarLabel.textContent = fmt(loss, 2) + " " + unit;
} else {
setBarFill(profitBar, 0);
setBarFill(lossBar, 0);
if (profitBarLabel) profitBarLabel.textContent = d.win_count ? "0 USDC" : "—";
if (lossBarLabel) lossBarLabel.textContent = d.loss_count ? "0 USDC" : "—";
if (profitBarLabel) profitBarLabel.textContent = d.win_count ? "0 " + unit : "—";
if (lossBarLabel) lossBarLabel.textContent = d.loss_count ? "0 " + unit : "—";
}
const winHold = Number(d.avg_win_hold_sec) || 0;