Show average profit and loss in option stats panel.

Expose avg_win and avg_loss from stats API and update chart labels and values to match the average-based P/L ratio.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-11 09:29:26 +08:00
parent bf2d668d3c
commit 68733eb4f9
4 changed files with 17 additions and 13 deletions
+8 -8
View File
@@ -800,12 +800,12 @@
}
if (closedEl) closedEl.textContent = String(d.total_closed || 0);
if (profitEl) {
profitEl.textContent = d.total_profit != null && d.total_profit > 0
? fmt(d.total_profit, 2) + " USDC" : (d.total_closed ? "0 USDC" : "—");
profitEl.textContent = d.avg_win != null && d.avg_win > 0
? fmt(d.avg_win, 2) + " USDC" : (d.win_count ? "0 USDC" : "—");
}
if (lossEl) {
lossEl.textContent = d.total_loss != null && d.total_loss > 0
? fmt(d.total_loss, 2) + " USDC" : (d.total_closed ? "0 USDC" : "—");
lossEl.textContent = d.avg_loss != null && d.avg_loss > 0
? fmt(d.avg_loss, 2) + " USDC" : (d.loss_count ? "0 USDC" : "—");
}
if (avgHoldEl) avgHoldEl.textContent = fmtDuration(d.avg_hold_sec);
if (winHoldEl) winHoldEl.textContent = fmtDuration(d.avg_win_hold_sec);
@@ -868,8 +868,8 @@
if (ring) ring.style.setProperty("--win-pct", String(winRate));
if (ringLabel) ringLabel.textContent = d.total_closed ? winRate.toFixed(0) + "%" : "0%";
const profit = Math.max(0, Number(d.total_profit) || 0);
const loss = Math.max(0, Number(d.total_loss) || 0);
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);
@@ -879,8 +879,8 @@
} else {
setBarFill(profitBar, 0);
setBarFill(lossBar, 0);
if (profitBarLabel) profitBarLabel.textContent = d.total_closed ? "0 USDC" : "—";
if (lossBarLabel) lossBarLabel.textContent = d.total_closed ? "0 USDC" : "—";
if (profitBarLabel) profitBarLabel.textContent = d.win_count ? "0 USDC" : "—";
if (lossBarLabel) lossBarLabel.textContent = d.loss_count ? "0 USDC" : "—";
}
const winHold = Number(d.avg_win_hold_sec) || 0;