(function (global) { "use strict"; function fmt(v, d) { if (v === null || v === undefined || Number.isNaN(Number(v))) return "—"; return Number(v).toFixed(d == null ? 2 : d); } function fmtDisplay(v, fallback) { if (v !== null && v !== undefined && String(v).trim() !== "") return String(v); if (fallback !== undefined) return fmtDisplay(fallback); return "—"; } function fmtOptionPx(v, tickSz) { if (v === null || v === undefined || Number.isNaN(Number(v))) return "—"; const n = Number(v); const tick = Number(tickSz); if (!tickSz || Number.isNaN(tick) || tick <= 0) return String(n); let decimals = 0; if (tick < 1) decimals = Math.max(0, -Math.round(Math.log10(tick))); else if (String(tick).indexOf(".") >= 0) decimals = String(tick).split(".")[1].length; return n.toFixed(decimals).replace(/\.?0+$/, "") || "0"; } function fmtUsdc(v) { if (v === null || v === undefined || Number.isNaN(Number(v))) return "—"; return Number(v).toFixed(2); } function optTypeLabel(t) { return (t || "").toUpperCase() === "P" ? "看跌 Put" : "看涨 Call"; } function pnlCls(upl, hub) { if (upl > 0) return hub ? "pnl-pos" : "pos-pnl-profit"; if (upl < 0) return hub ? "pnl-neg" : "pos-pnl-loss"; return ""; } function fmtCloseLevels(preview, tickSz) { const levels = ((preview && preview.levels) || []).slice(0, 5); if (!levels.length) return "—"; return levels.map(function (x, idx) { const levelNo = x.level != null ? x.level : idx + 1; return "买" + levelNo + " " + fmtOptionPx(x.px, tickSz); }).join(" · "); } function fmtClosePreview(preview, premiumPaid, hub) { if (!preview || preview.total_received == null) return "—"; const recvTxt = fmtUsdc(preview.total_received); let cls = ""; const prem = Number(premiumPaid); const recv = Number(preview.total_received); if (!Number.isNaN(prem) && !Number.isNaN(recv)) { if (recv > prem) cls = " " + pnlCls(1, hub); else if (recv < prem) cls = " " + pnlCls(-1, hub); } return '' + recvTxt + " USDC"; } function expiryCdHtml(expMs) { const ms = expMs != null && expMs !== "" ? String(expMs) : ""; if (!ms) return "—"; return ''; } function renderCardInner(p, opts) { opts = opts || {}; const hub = !!opts.hub; const readOnly = !!opts.readOnly; const upl = p.upl; const uplCls = pnlCls(upl, hub); const sideCls = (p.opt_type || "").toUpperCase() === "P" ? "pos-side-short" : "pos-side-long"; 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 tickSz = p.tick_sz; 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)); let headActions = ""; if (!readOnly) { const closeSheets = p.avail_pos != null && Number(p.avail_pos) > 0 ? p.avail_pos : p.pos; headActions = '
' + '' + "
"; } return ( '
' + '
' + (p.inst_id || "") + "" + '' + optTypeLabel(p.opt_type) + "
" + headActions + "
" + '
' + '行权价: ' + fmt(p.strike, 0) + "" + '张数: ' + fmt(p.pos, 0) + " · 币量 " + fmt(p.eth_amount, 4) + "" + (expAttr ? '到期倒计时: ' + expiryCdHtml(expAttr) + "" : "") + "
" + '
' + '
权利金' + premTxt + " USDC
" + '
开仓均价' + avgTxt + "
" + '
标记价' + markTxt + "
" + '
指数价' + fmt(p.idx_px, 0) + "
" + '
到期平衡' + fmt(p.expiry_be_px, 0) + "
" + '
平掉回本' + fmt(p.close_be_px, 0) + "
" + '
浮盈亏' + fmt(p.upl, 2) + "
" + '
收益率' + (p.upl_ratio_pct != null ? fmt(p.upl_ratio_pct, 2) + "%" : "—") + "
" + '
买盘深度' + fmtCloseLevels(closePreview, tickSz) + "
" + '
按买盘回收' + fmtClosePreview(closePreview, p.premium_paid, hub) + "
" + "
" + (p.target_index != null ? (function () { const eth = p.eth_amount != null ? Number(p.eth_amount) : (Number(p.pos) > 0 ? Number(p.pos) * Number(p.ct_mult || 0.01) : null); const strike = Number(p.strike); const tgt = Number(p.target_index); const prem = Number(p.premium_paid); let profit = null; let value = null; if (Number.isFinite(tgt) && Number.isFinite(strike) && eth > 0) { const o = String(p.opt_type || "").toUpperCase(); const intrinsic = o === "C" ? Math.max(0, tgt - strike) : o === "P" ? Math.max(0, strike - tgt) : null; if (intrinsic != null) { value = Math.round(intrinsic * eth * 100) / 100; if (Number.isFinite(prem)) profit = Math.round((value - prem) * 100) / 100; } } const profitTxt = profit == null ? "—" : ((profit > 0 ? "+" : "") + fmtUsdc(profit) + " USDC"); const profitCls = profit > 0 ? " pnl-pos" : profit < 0 ? " pnl-neg" : ""; return ( '
' + '委托' + '目标 ' + fmt(p.target_index, 1) + "" + '价值 ' + (value == null ? "—" : fmtUsdc(value) + " USDC") + "" + '预估盈利 ' + profitTxt + "" + '监控中 · 到位按买一限价平
' ); })() : "") ); } function renderCard(p, opts) { opts = opts || {}; const hub = !!opts.hub; const extraCls = hub ? " hub-pos-card hub-opt-pos-card" : " opt-pos-card"; return ( '
' + renderCardInner(p, opts) + "
" ); } global.OptionsPositionCards = { renderCardInner: renderCardInner, renderCard: renderCard, }; })(typeof window !== "undefined" ? window : globalThis);