Polish option close depth display.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-11 08:57:19 +08:00
parent 6e45604d93
commit e8a55a0f85
3 changed files with 218 additions and 7 deletions
+38 -6
View File
@@ -188,12 +188,36 @@
function fmtBidDepth(levels) {
const bids = (levels || []).slice(0, 5);
if (!bids.length) return "—";
return bids.map(function (x, idx) {
return "买" + (idx + 1) + " " + fmtPxSz(x.px, x.sz);
}).join(" · ");
return '<div class="opt-bid-depth">' + bids.map(function (x, idx) {
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-price">' + fmt(x.px, 4) + "</span>" +
'<span class="opt-bid-size">' + fmt(x.sz, 0) + "张</span>" +
"</span>"
);
}).join("") + "</div>";
}
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>"
);
}
function fmtClosePreviewText(preview) {
if (!preview || preview.total_received == null) return "—";
let text = fmt(preview.total_received, 4) + " USDC";
if (preview.covered_sheets != null) {
@@ -221,6 +245,14 @@
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);
@@ -506,8 +538,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"><span class="pos-label">买盘深度</span><span class="pos-value">' + fmtBidDepth(p.bid_depth) + "</span></div>" +
'<div class="pos-cell"><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">' + 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"><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>" +
@@ -611,7 +643,7 @@
const msg = [
"按最多5档买盘拆分限价卖出?",
"合约: " + inst,
"预计收回: " + fmtClosePreview(preview),
"预计收回: " + fmtClosePreviewText(preview),
preview.estimated_pnl != null ? "预估盈亏: " + fmt(preview.estimated_pnl, 4) + " USDC" : "",
"",
fmtPreviewLevels(preview),