Fix hub options float summary blank when bid book is invalid.
Stop treating total_received=0 as a real bid recycle, fall back to exchange upl for display totals, and keep row/summary aligned. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3821,6 +3821,30 @@
|
||||
return vals.reduce((s, v) => s + v, 0);
|
||||
}
|
||||
|
||||
function optionsRowDisplayPnl(p) {
|
||||
if (!p || typeof p !== "object") return null;
|
||||
const preview = p.close_preview || {};
|
||||
// bid 无效时 total_received 常为 0,不能用 0−权利金冒充净亏
|
||||
if (preview.bid_invalid) {
|
||||
const upl = p.upl != null ? Number(p.upl) : NaN;
|
||||
return Number.isFinite(upl) ? upl : null;
|
||||
}
|
||||
let net = preview.estimated_pnl;
|
||||
const covered = Number(preview.covered_sheets);
|
||||
if (
|
||||
net == null &&
|
||||
preview.total_received != null &&
|
||||
Number.isFinite(covered) &&
|
||||
covered > 0 &&
|
||||
p.premium_paid != null
|
||||
) {
|
||||
net = Number(preview.total_received) - Number(p.premium_paid);
|
||||
}
|
||||
if (net != null && Number.isFinite(Number(net))) return Number(net);
|
||||
const upl = p.upl != null ? Number(p.upl) : NaN;
|
||||
return Number.isFinite(upl) ? upl : null;
|
||||
}
|
||||
|
||||
function optionsBalanceFields(opt) {
|
||||
if (!opt || typeof opt !== "object") {
|
||||
return { funding: null, trading: null, upl: null };
|
||||
@@ -3828,6 +3852,23 @@
|
||||
const bal =
|
||||
opt.balances && typeof opt.balances === "object" ? opt.balances : {};
|
||||
const pick = (a, b) => (a != null && a !== "" ? a : b);
|
||||
let upl =
|
||||
opt.upl_total_usdc != null && Number.isFinite(Number(opt.upl_total_usdc))
|
||||
? Number(opt.upl_total_usdc)
|
||||
: null;
|
||||
if (upl == null) {
|
||||
const pos = Array.isArray(opt.positions) ? opt.positions : [];
|
||||
let sum = 0;
|
||||
let found = false;
|
||||
pos.forEach((p) => {
|
||||
const n = optionsRowDisplayPnl(p);
|
||||
if (n != null) {
|
||||
sum += n;
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
if (found) upl = sum;
|
||||
}
|
||||
return {
|
||||
funding: sumUsdtEquiv(
|
||||
pick(bal.funding_usdt, opt.funding_usdt),
|
||||
@@ -3837,10 +3878,7 @@
|
||||
pick(bal.trading_usdt, opt.trading_usdt),
|
||||
pick(bal.trading_usdc, opt.trading_usdc)
|
||||
),
|
||||
upl:
|
||||
opt.upl_total_usdc != null && Number.isFinite(Number(opt.upl_total_usdc))
|
||||
? Number(opt.upl_total_usdc)
|
||||
: null,
|
||||
upl,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3915,10 +3953,7 @@
|
||||
? "Put"
|
||||
: p.opt_type || "—";
|
||||
const preview = p.close_preview || {};
|
||||
let net = preview.estimated_pnl;
|
||||
if (net == null && preview.total_received != null && p.premium_paid != null) {
|
||||
net = Number(preview.total_received) - Number(p.premium_paid);
|
||||
}
|
||||
let net = optionsRowDisplayPnl(p);
|
||||
let roi = preview.estimated_pnl_ratio_pct;
|
||||
if (roi == null && net != null && Number(p.premium_paid) > 0) {
|
||||
roi = (Number(net) / Number(p.premium_paid)) * 100;
|
||||
|
||||
Reference in New Issue
Block a user