Include options unrealized PnL in OKX instance header realtime PnL total.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-08 11:05:52 +08:00
parent 75a64c5d24
commit f68197b775
6 changed files with 102 additions and 2 deletions
+23 -1
View File
@@ -1046,6 +1046,26 @@ function sumOrdersFloatPnl(orders){
});
return found ? total : null;
}
function combineRealtimeFloatPnl(perpTotal, optionsTotal){
let total = 0, found = false;
[perpTotal, optionsTotal].forEach(v=>{
if(v != null && !Number.isNaN(Number(v))){
total += Number(v);
found = true;
}
});
return found ? total : null;
}
function paintRealtimePnlFromSnapshot(data){
if(!data) return;
const perp = data.order_prices && data.order_prices.length
? sumOrdersFloatPnl(data.order_prices)
: null;
const combined = combineRealtimeFloatPnl(perp, data.options_unrealized_pnl);
if(combined !== null || perp !== null || data.options_unrealized_pnl != null){
paintRealtimePnl(combined);
}
}
function formatOptionsFundingLabel(usdc, usdt) {
const parts = [];
@@ -1319,7 +1339,9 @@ function refreshPriceSnapshotConditional(){
tickOrderHoldDurations();
}
if(data.order_prices && data.order_prices.length){
paintRealtimePnl(sumOrdersFloatPnl(data.order_prices));
paintRealtimePnlFromSnapshot(data);
} else if (typeof data.options_unrealized_pnl !== "undefined") {
paintRealtimePnlFromSnapshot(data);
}
}).catch(()=>{});
}