Simplify option close depth display.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-11 09:04:17 +08:00
parent e8a55a0f85
commit 1b31c61aac
3 changed files with 26 additions and 87 deletions
+9 -26
View File
@@ -185,16 +185,16 @@
return price + "/" + size;
}
function fmtBidDepth(levels) {
const bids = (levels || []).slice(0, 5);
if (!bids.length) return "—";
return '<div class="opt-bid-depth">' + bids.map(function (x, idx) {
function fmtCloseLevels(preview) {
const levels = ((preview && preview.levels) || []).slice(0, 5);
if (!levels.length) return "—";
return '<div class="opt-bid-depth">' + levels.map(function (x, idx) {
const levelNo = x.level != null ? x.level : idx + 1;
const levelCls = idx === 0 ? " opt-bid-level--best" : "";
return (
'<span class="opt-bid-level' + levelCls + '">' +
'<span class="opt-bid-rank">买' + (idx + 1) + "</span>" +
'<span class="opt-bid-rank">买' + levelNo + "</span>" +
'<span class="opt-bid-price">' + fmt(x.px, 4) + "</span>" +
'<span class="opt-bid-size">' + fmt(x.sz, 0) + "张</span>" +
"</span>"
);
}).join("") + "</div>";
@@ -202,18 +202,10 @@
function fmtClosePreview(preview) {
if (!preview || preview.total_received == null) return "—";
const missing = Number(preview.uncovered_sheets || 0);
const covered = Number(preview.covered_sheets || 0);
const pnl = preview.estimated_pnl;
const pnlCls = pnlClsName(pnl);
return (
'<div class="opt-close-preview">' +
'<div class="opt-close-main">' + fmt(preview.total_received, 4) + '<span>USDC</span></div>' +
'<div class="opt-close-sub">' +
'<span class="opt-close-pill opt-close-pill--ok">覆盖 ' + covered + "张</span>" +
(missing > 0 ? '<span class="opt-close-pill opt-close-pill--warn">缺 ' + missing + "张</span>" : "") +
(pnl != null ? '<span class="opt-close-pnl ' + pnlCls + '">' + (Number(pnl) > 0 ? "+" : "") + fmt(pnl, 4) + "</span>" : "") +
"</div></div>"
"</div>"
);
}
@@ -245,14 +237,6 @@
return "";
}
function pnlClsName(v) {
if (v === null || v === undefined || Number.isNaN(Number(v))) return "";
const n = Number(v);
if (n > 0) return "is-profit";
if (n < 0) return "is-loss";
return "";
}
function estimateExpiryProfit(optType, strike, targetIdx, entryPx, ethAmount) {
if (strike == null || targetIdx == null || entryPx == null || ethAmount == null) return null;
const amt = Number(ethAmount);
@@ -517,7 +501,6 @@
const expMs = p.exp_time_ms != null ? p.exp_time_ms : p.exp_time;
const expAttr = expMs != null && expMs !== "" ? String(expMs) : "";
const closePreview = p.close_preview || {};
const closePreviewCls = pnlCls(closePreview.estimated_pnl);
const closeSheets = p.avail_pos != null && Number(p.avail_pos) > 0 ? p.avail_pos : p.pos;
return (
'<div class="pos-card-head">' +
@@ -538,8 +521,8 @@
'<div class="pos-cell"><span class="pos-label">开仓均价</span><span class="pos-value">' + fmt(p.avg_px, 4) + "</span></div>" +
'<div class="pos-cell"><span class="pos-label">标记价</span><span class="pos-value">' + fmt(p.mark_px, 4) + "</span></div>" +
'<div class="pos-cell"><span class="pos-label">指数价</span><span class="pos-value">' + fmt(p.idx_px, 0) + "</span></div>" +
'<div class="pos-cell opt-pos-cell--depth"><span class="pos-label">买盘深度</span><span class="pos-value">' + fmtBidDepth(p.bid_depth) + "</span></div>" +
'<div class="pos-cell opt-pos-cell--close"><span class="pos-label">按买盘收回</span><span class="pos-value ' + closePreviewCls + '">' + fmtClosePreview(closePreview) + "</span></div>" +
'<div class="pos-cell opt-pos-cell--depth"><span class="pos-label">买盘深度</span><span class="pos-value">' + fmtCloseLevels(closePreview) + "</span></div>" +
'<div class="pos-cell opt-pos-cell--close"><span class="pos-label">按买盘收回</span><span class="pos-value">' + fmtClosePreview(closePreview) + "</span></div>" +
'<div class="pos-cell"><span class="pos-label">到期平衡</span><span class="pos-value">' + fmt(p.expiry_be_px, 0) + "</span></div>" +
'<div class="pos-cell"><span class="pos-label">平掉回本</span><span class="pos-value">' + fmt(p.close_be_px, 0) + "</span></div>" +
'<div class="pos-cell"><span class="pos-label">浮盈亏</span><span class="pos-value ' + uplCls + '">' + fmt(p.upl, 2) + "</span></div>" +