feat: options stats profit/loss totals and history delete

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-07 10:31:09 +08:00
parent 5fdfc67438
commit 2d52bfac80
4 changed files with 77 additions and 8 deletions
+5
View File
@@ -2597,6 +2597,11 @@ html[data-theme="light"] .settings-export-link {
font-size: 1.1rem;
font-weight: 600;
}
.options-history-table-wrap .opt-history-del {
font-size: 0.72rem;
padding: 2px 8px;
min-height: 24px;
}
.options-pos-history-card {
flex: 1;
min-height: 0;
+36 -6
View File
@@ -383,10 +383,12 @@
const winEl = document.getElementById("opt-stats-winrate");
const plrEl = document.getElementById("opt-stats-plr");
const closedEl = document.getElementById("opt-stats-closed");
const profitEl = document.getElementById("opt-stats-profit");
const lossEl = document.getElementById("opt-stats-loss");
if (!d.ok) {
if (winEl) winEl.textContent = "—";
if (plrEl) plrEl.textContent = "—";
if (closedEl) closedEl.textContent = "—";
[winEl, plrEl, closedEl, profitEl, lossEl].forEach(function (el) {
if (el) el.textContent = "—";
});
return;
}
if (winEl) winEl.textContent = d.total_closed ? d.win_rate + "%" : "0%";
@@ -394,6 +396,27 @@
plrEl.textContent = d.profit_loss_ratio != null ? String(d.profit_loss_ratio) : "—";
}
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, 4) + " USDC" : (d.total_closed ? "0 USDC" : "—");
}
if (lossEl) {
lossEl.textContent = d.total_loss != null && d.total_loss > 0
? fmt(d.total_loss, 4) + " USDC" : (d.total_closed ? "0 USDC" : "—");
}
}
async function deleteHistoryRow(id, status) {
const warn = status === "open"
? "该记录仍为持仓中,仅删除本地记录,不影响交易所持仓。确认删除?"
: "确认删除该条期权历史记录?";
if (!confirm(warn)) return;
const r = await apiJson("/api/options/history/" + encodeURIComponent(id), { method: "DELETE" });
if (!r.ok) {
alert(r.msg || "删除失败");
return;
}
refreshAllPositions();
}
async function refreshHistory() {
@@ -402,7 +425,7 @@
tbody.innerHTML = "";
const list = (d.ok && d.history) || [];
if (!list.length) {
tbody.innerHTML = '<tr><td colspan="6" class="muted">暂无历史记录</td></tr>';
tbody.innerHTML = '<tr><td colspan="7" class="muted">暂无历史记录</td></tr>';
return;
}
list.forEach(function (h) {
@@ -410,15 +433,22 @@
const prem = h.status === "closed" ? h.premium_received : h.premium_paid;
const pnl = h.realized_pnl;
const pnlTxt = pnl != null ? fmt(pnl, 4) : "—";
const pnlCls = pnl > 0 ? "pos-pnl-profit" : pnl < 0 ? "pos-pnl-loss" : "";
tr.innerHTML =
"<td><code>" + (h.inst_id || "") + "</code></td>" +
"<td>" + fmt(h.sheets, 0) + "</td>" +
"<td>" + fmt(prem, 4) + "</td>" +
"<td>" + (h.status === "closed" ? "已平" : "持仓中") + "</td>" +
"<td>" + pnlTxt + "</td>" +
"<td>" + (h.closed_at || h.created_at || "—") + "</td>";
'<td class="' + pnlCls + '">' + pnlTxt + "</td>" +
"<td>" + (h.closed_at || h.created_at || "—") + "</td>" +
'<td><button type="button" class="btn-secondary btn-sm opt-history-del" data-id="' + h.id + '" data-status="' + (h.status || "") + '">删除</button></td>';
tbody.appendChild(tr);
});
tbody.querySelectorAll(".opt-history-del").forEach(function (btn) {
btn.addEventListener("click", function () {
deleteHistoryRow(btn.getAttribute("data-id"), btn.getAttribute("data-status"));
});
});
}
function refreshAllPositions() {