feat: options stats profit/loss totals and history delete
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user