币本位数据统计改为U展示,已平盈亏按指数折U与浮盈口径一致。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-21 06:46:11 +08:00
parent d60c6ad710
commit fc24114142
3 changed files with 117 additions and 13 deletions
+19 -11
View File
@@ -2340,7 +2340,12 @@
}
}
function paintPnlStat(el, value) {
function statsPnlUnit(d) {
if (d && d.pnl_unit) return String(d.pnl_unit);
return isCoinMarginMode() ? "U" : "USDC";
}
function paintPnlStat(el, value, unit) {
if (!el) return;
if (value == null || value === "" || Number.isNaN(Number(value))) {
el.textContent = "—";
@@ -2348,7 +2353,8 @@
return;
}
const n = Number(value);
el.textContent = (n > 0 ? "+" : "") + fmt(n, 2) + " USDC";
const u = unit || "USDC";
el.textContent = (n > 0 ? "+" : "") + fmt(n, 2) + " " + u;
el.classList.toggle("pos-pnl-profit", n > 0);
el.classList.toggle("pos-pnl-loss", n < 0);
}
@@ -2378,9 +2384,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) : "—";
@@ -2388,11 +2395,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);
@@ -2455,19 +2462,20 @@
if (ring) ring.style.setProperty("--win-pct", String(winRate));
if (ringLabel) ringLabel.textContent = d.total_closed ? winRate.toFixed(0) + "%" : "0%";
const unit = statsPnlUnit(d);
const profit = Math.max(0, Number(d.avg_win) || 0);
const loss = Math.max(0, Number(d.avg_loss) || 0);
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;