单独期权下单预估改为显示盈亏比

目标位指数仅作到期实值参考,展示盈利÷本合约权利金;持仓目标行同步显示盈亏比。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-11 17:10:04 +08:00
parent 38e3e00fe9
commit 3d7d754ba3
2 changed files with 43 additions and 13 deletions
+37 -7
View File
@@ -856,6 +856,19 @@
return Math.round((value - prem) * 100) / 100;
}
/** 盈亏比 = 盈利金额 / 本合约权利金(目标位仅作到期实值参考). */
function estimateProfitRr(profit, totalPremium) {
const pnl = Number(profit);
const prem = Number(totalPremium);
if (!Number.isFinite(pnl) || !Number.isFinite(prem) || prem <= 0) return null;
return Math.round((pnl / prem) * 100) / 100;
}
function fmtProfitRr(v) {
if (v === null || v === undefined || Number.isNaN(Number(v))) return "—";
return Number(v).toFixed(2);
}
function calcContractLeverage(indexPx, ethAmount, totalPremium) {
if (indexPx == null || ethAmount == null || totalPremium == null) return null;
const idx = Number(indexPx);
@@ -897,7 +910,7 @@
const levEl = document.getElementById("opt-order-leverage");
const valueEl = document.getElementById("opt-est-value");
const profitEl = document.getElementById("opt-est-profit");
const targetLevEl = document.getElementById("opt-est-leverage");
const rrEl = document.getElementById("opt-est-rr") || document.getElementById("opt-est-leverage");
const targetEl = document.getElementById("opt-target-idx");
const q = state.orderQuote;
if (!q || !q.ok || !q.can_open) {
@@ -907,7 +920,10 @@
profitEl.textContent = "—";
profitEl.className = "v";
}
if (targetLevEl) targetLevEl.textContent = "—";
if (rrEl) {
rrEl.textContent = "—";
rrEl.className = "v";
}
return;
}
const sz = q.sizing || {};
@@ -922,10 +938,14 @@
valueEl.textContent = "—";
profitEl.textContent = "—";
profitEl.className = "v";
if (targetLevEl) targetLevEl.textContent = "—";
if (rrEl) {
rrEl.textContent = "—";
rrEl.className = "v";
}
} else {
const value = estimateExpiryValue(q.opt_type, q.strike, Number(targetRaw), ethAmount);
const profit = estimateExpiryProfit(q.opt_type, q.strike, Number(targetRaw), ethAmount, premium);
const rr = estimateProfitRr(profit, premium);
if (value == null || Number.isNaN(value)) {
valueEl.textContent = "—";
} else {
@@ -938,8 +958,15 @@
profitEl.textContent = fmtUsdcSigned(profit);
profitEl.className = "v " + pnlCls(profit);
}
const targetLev = calcContractLeverage(Number(targetRaw), ethAmount, premium);
if (targetLevEl) targetLevEl.textContent = fmtLeverage(targetLev);
if (rrEl) {
if (rr == null || Number.isNaN(rr)) {
rrEl.textContent = "—";
rrEl.className = "v";
} else {
rrEl.textContent = fmtProfitRr(rr);
rrEl.className = "v " + pnlCls(rr);
}
}
}
}
}
@@ -1431,12 +1458,15 @@
function formatTargetEstimateHtml(optType, strike, targetIdx, ethAmount, premiumPaid) {
const value = estimateExpiryValue(optType, strike, targetIdx, ethAmount);
const profit = estimateExpiryProfit(optType, strike, targetIdx, ethAmount, premiumPaid);
if (value == null && profit == null) return "";
const rr = estimateProfitRr(profit, premiumPaid);
if (value == null && profit == null && rr == null) return "";
let html = '<span class="opt-target-est">';
html += '<span class="opt-target-est-item"><span class="k">价值</span><span class="v">' +
(value == null ? "—" : fmtUsdc(value) + " USDC") + "</span></span>";
html += '<span class="opt-target-est-item"><span class="k">预估盈利</span><span class="v ' + pnlCls(profit) + '">' +
(profit == null ? "—" : fmtUsdcSigned(profit)) + "</span></span>";
html += '<span class="opt-target-est-item"><span class="k">盈亏比</span><span class="v ' + pnlCls(rr) + '">' +
(rr == null ? "—" : fmtProfitRr(rr)) + "</span></span>";
html += "</span>";
return html;
}
@@ -1500,7 +1530,7 @@
: "") +
estHtml +
'<span class="muted opt-target-row-hint">' +
(armed ? "监控中 · 到位按买一限价平" : "输入后设定 · 到位按买一限价平 · 到期即止损") +
(armed ? "监控中 · 目标位参考 · 到位按买一限价平" : "目标位参考(到期实值估盈亏比) · 到位按买一限价平 · 到期即止损") +
"</span>" +
"</div>"
);