Fix option history to full closes only, 2-decimal USDC, restore hide-delete.
Filter OKX positions-history to type 2/3/6, format premium and bid recovery to 2 decimals, and allow locally hiding rows via delete button. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -215,7 +215,7 @@
|
||||
|
||||
function fmtUsdc(v) {
|
||||
if (v === null || v === undefined || Number.isNaN(Number(v))) return "—";
|
||||
return Number(v).toFixed(4).replace(/\.?0+$/, "") || "0";
|
||||
return Number(v).toFixed(2);
|
||||
}
|
||||
|
||||
function fmtClosePreview(preview, premiumPaid) {
|
||||
@@ -525,7 +525,7 @@
|
||||
const closePreview = p.close_preview || {};
|
||||
const closeSheets = p.avail_pos != null && Number(p.avail_pos) > 0 ? p.avail_pos : p.pos;
|
||||
const tickSz = p.tick_sz;
|
||||
const premTxt = fmtDisplay(p.premium_paid_fmt, p.premium_paid != null ? fmt(p.premium_paid, 4).replace(/\.?0+$/, "") : null);
|
||||
const premTxt = fmtDisplay(p.premium_paid_fmt, p.premium_paid != null ? fmtUsdc(p.premium_paid) : null);
|
||||
const avgTxt = fmtDisplay(p.avg_px_fmt, fmtOptionPx(p.avg_px, tickSz));
|
||||
const markTxt = fmtDisplay(p.mark_px_fmt, fmtOptionPx(p.mark_px, tickSz));
|
||||
return (
|
||||
@@ -899,6 +899,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteHistoryRow(key, status) {
|
||||
const warn = status === "open"
|
||||
? "该记录仍为持仓中,仅从列表隐藏,不影响交易所持仓.确认删除?"
|
||||
: "确认从列表隐藏该条历史记录?";
|
||||
if (!confirm(warn)) return;
|
||||
const r = await apiJson("/api/options/history/" + encodeURIComponent(key), { method: "DELETE" });
|
||||
if (!r.ok) {
|
||||
alert(r.msg || "删除失败");
|
||||
return;
|
||||
}
|
||||
refreshAllPositions();
|
||||
}
|
||||
|
||||
function optHistoryStatus(h) {
|
||||
if (h.status_label) return h.status_label;
|
||||
if (h.status === "open") return "持仓中";
|
||||
@@ -921,26 +934,33 @@
|
||||
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) {
|
||||
const tr = document.createElement("tr");
|
||||
const premTxt = fmtDisplay(h.premium_paid_fmt, h.premium_paid != null ? fmt(h.premium_paid, 2) : null);
|
||||
const premTxt = fmtDisplay(h.premium_paid_fmt, h.premium_paid != null ? fmtUsdc(h.premium_paid) : null);
|
||||
const isOpen = h.status === "open";
|
||||
const pnl = isOpen ? null : h.realized_pnl;
|
||||
const pnlTxt = pnl != null ? fmt(pnl, 2) : "—";
|
||||
const pnlCls = pnl > 0 ? "pos-pnl-profit" : pnl < 0 ? "pos-pnl-loss" : "";
|
||||
const timeTxt = (h.closed_at || h.created_at || "—").replace("T", " ").slice(0, 19);
|
||||
const histKey = h.history_key || "";
|
||||
tr.innerHTML =
|
||||
'<td class="opt-hist-inst"><code>' + (h.inst_id || "") + "</code></td>" +
|
||||
"<td>" + fmt(h.sheets, 0) + "</td>" +
|
||||
"<td>" + premTxt + "</td>" +
|
||||
"<td>" + optHistoryStatusHtml(h) + "</td>" +
|
||||
'<td class="' + pnlCls + '">' + pnlTxt + "</td>" +
|
||||
'<td class="opt-hist-time">' + timeTxt + "</td>";
|
||||
'<td class="opt-hist-time">' + timeTxt + "</td>" +
|
||||
'<td><button type="button" class="btn-secondary btn-sm opt-history-del" data-key="' + histKey + '" 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-key"), btn.getAttribute("data-status"));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function refreshAllPositions() {
|
||||
|
||||
Reference in New Issue
Block a user