币本位盈亏双显ETH/U(按指数换算);平仓卖币改为卖光交易户可用余额
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -897,6 +897,31 @@
|
||||
return fmtUsdc(n);
|
||||
}
|
||||
|
||||
/** 币本位盈亏双显:0.0018 ETH / 4.09U(按指数/现货价换算). */
|
||||
function spotPxOf(p) {
|
||||
const n = Number(p && (p.idx_px != null ? p.idx_px : p.idxPx != null ? p.idxPx : p.index_px));
|
||||
return Number.isFinite(n) && n > 0 ? n : null;
|
||||
}
|
||||
|
||||
function fmtCoinUsdtDual(coinAmt, spotPx, ccy, signed) {
|
||||
if (coinAmt === null || coinAmt === undefined || Number.isNaN(Number(coinAmt))) return "—";
|
||||
const n = Number(coinAmt);
|
||||
const unit = String(ccy || "ETH").toUpperCase();
|
||||
if (unit !== "ETH" && unit !== "BTC") {
|
||||
const sign = signed && n > 0 ? "+" : "";
|
||||
return sign + fmtUsdc(n) + "U";
|
||||
}
|
||||
const absCoin = Math.abs(n).toFixed(8).replace(/\.?0+$/, "") || "0";
|
||||
const coinSign = n < 0 ? "-" : signed && n > 0 ? "+" : "";
|
||||
const coinTxt = coinSign + absCoin + " " + unit;
|
||||
const px = Number(spotPx);
|
||||
if (!Number.isFinite(px) || !(px > 0)) return coinTxt;
|
||||
const u = n * px;
|
||||
const absU = Math.abs(u).toFixed(2);
|
||||
const uSign = u < 0 ? "-" : signed && u > 0 ? "+" : "";
|
||||
return coinTxt + " / " + uSign + absU + "U";
|
||||
}
|
||||
|
||||
function fmtPremiumAmtSigned(v, ccy) {
|
||||
if (v === null || v === undefined || Number.isNaN(Number(v))) return "—";
|
||||
const n = Number(v);
|
||||
@@ -904,6 +929,15 @@
|
||||
return sign + fmtPremiumAmt(n, ccy) + " " + (String(ccy || "USDC").toUpperCase());
|
||||
}
|
||||
|
||||
function fmtNetPnlDual(net, p) {
|
||||
const ccy = posPremiumCcy(p);
|
||||
if (ccy === "USDC") {
|
||||
if (net == null || Number.isNaN(Number(net))) return "—";
|
||||
return fmtUsdc(Number(net)) + "U";
|
||||
}
|
||||
return fmtCoinUsdtDual(net, spotPxOf(p), ccy, true);
|
||||
}
|
||||
|
||||
function fmtClosePreview(preview, premiumPaid, p) {
|
||||
if (!preview || preview.total_received == null) return "—";
|
||||
const ccy = posPremiumCcy(p);
|
||||
@@ -1614,7 +1648,7 @@
|
||||
const markTxt = p.mark_px != null ? fmtOptionPx(p.mark_px, tickSz) : fmtDisplay(p.mark_px_fmt);
|
||||
const netTxt = closePreview.bid_invalid || net == null
|
||||
? "—"
|
||||
: (fmtPremiumAmt(net, premCcy) + (coinPos ? (" " + premCcy) : ""));
|
||||
: fmtNetPnlDual(net, p);
|
||||
return (
|
||||
'<div class="pos-card-head">' +
|
||||
'<div class="pos-card-symbol"><strong>' + (p.inst_id || "") + '</strong>' +
|
||||
@@ -1873,7 +1907,7 @@
|
||||
? '<span class="opt-pos-bar-cd">到期 <span class="opt-expiry-cd" data-opt-exp-ms="' + expAttr + '">—</span></span>'
|
||||
: "") +
|
||||
'<span class="opt-pos-bar-pnl ' + uplCls + '">' +
|
||||
(net == null ? "—" : (fmtPremiumAmt(net, posPremiumCcy(p)) + " " + posPremiumCcy(p))) + "</span>" +
|
||||
(net == null ? "—" : fmtNetPnlDual(net, p)) + "</span>" +
|
||||
'<span class="opt-pos-bar-roi ' + uplCls + '">' +
|
||||
(roi == null ? "—" : fmt(roi, 2) + "%") + "</span>" +
|
||||
"</span>" +
|
||||
|
||||
@@ -56,6 +56,39 @@
|
||||
return fmtUsdc(n);
|
||||
}
|
||||
|
||||
function spotPxOf(p) {
|
||||
const n = Number(p && (p.idx_px != null ? p.idx_px : p.idxPx != null ? p.idxPx : p.index_px));
|
||||
return Number.isFinite(n) && n > 0 ? n : null;
|
||||
}
|
||||
|
||||
function fmtCoinUsdtDual(coinAmt, spotPx, ccy, signed) {
|
||||
if (coinAmt === null || coinAmt === undefined || Number.isNaN(Number(coinAmt))) return "—";
|
||||
const n = Number(coinAmt);
|
||||
const unit = String(ccy || "ETH").toUpperCase();
|
||||
if (unit !== "ETH" && unit !== "BTC") {
|
||||
const sign = signed && n > 0 ? "+" : "";
|
||||
return sign + fmtUsdc(n) + "U";
|
||||
}
|
||||
const absCoin = Math.abs(n).toFixed(8).replace(/\.?0+$/, "") || "0";
|
||||
const coinSign = n < 0 ? "-" : signed && n > 0 ? "+" : "";
|
||||
const coinTxt = coinSign + absCoin + " " + unit;
|
||||
const px = Number(spotPx);
|
||||
if (!Number.isFinite(px) || !(px > 0)) return coinTxt;
|
||||
const u = n * px;
|
||||
const absU = Math.abs(u).toFixed(2);
|
||||
const uSign = u < 0 ? "-" : signed && u > 0 ? "+" : "";
|
||||
return coinTxt + " / " + uSign + absU + "U";
|
||||
}
|
||||
|
||||
function fmtNetPnlDual(net, p) {
|
||||
const ccy = posPremiumCcy(p);
|
||||
if (ccy === "USDC") {
|
||||
if (net == null || Number.isNaN(Number(net))) return "—";
|
||||
return fmtUsdc(Number(net)) + "U";
|
||||
}
|
||||
return fmtCoinUsdtDual(net, spotPxOf(p), ccy, true);
|
||||
}
|
||||
|
||||
function optTypeLabel(t) {
|
||||
return (t || "").toUpperCase() === "P" ? "看跌 Put" : "看涨 Call";
|
||||
}
|
||||
@@ -209,7 +242,7 @@
|
||||
const pnlCells = hidePnl
|
||||
? ""
|
||||
: '<div class="pos-cell"><span class="pos-label">净盈亏</span><span class="pos-value ' + uplCls + '">' +
|
||||
(net == null ? "—" : (fmtPremiumAmt(net, premCcy) + (premCcy !== "USDC" ? (" " + premCcy) : ""))) + "</span></div>" +
|
||||
(net == null ? "—" : fmtNetPnlDual(net, p)) + "</span></div>" +
|
||||
'<div class="pos-cell"><span class="pos-label">收益率</span><span class="pos-value ' + uplCls + '">' +
|
||||
(roi == null ? "—" : fmt(roi, 2) + "%") + "</span></div>";
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user