Fix intermittent loss of options positions and realtime PnL on refresh.
Use stale-while-revalidate for positions API and UI, throttle sync calls, and avoid overwriting displayed PnL with null on transient failures. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1081,6 +1081,16 @@ function paintRealtimePnl(v){
|
||||
pnlEl.classList.toggle("pnl-neg", n < 0);
|
||||
});
|
||||
}
|
||||
let lastRealtimePnl = null;
|
||||
function updateRealtimePnl(v){
|
||||
if(v != null && !Number.isNaN(Number(v))){
|
||||
lastRealtimePnl = Number(v);
|
||||
paintRealtimePnl(v);
|
||||
return;
|
||||
}
|
||||
if(lastRealtimePnl != null) return;
|
||||
paintRealtimePnl(v);
|
||||
}
|
||||
function sumOrdersFloatPnl(orders){
|
||||
if(!orders || !orders.length) return null;
|
||||
let total = 0, found = false;
|
||||
@@ -1153,7 +1163,7 @@ function applyAccountSnapshot(data){
|
||||
setFundsFieldText("options-trading-usdc", `${Number(data.options_trading_usdc).toFixed(2)} USDC`);
|
||||
}
|
||||
if(typeof data.unrealized_pnl !== "undefined"){
|
||||
paintRealtimePnl(data.unrealized_pnl);
|
||||
updateRealtimePnl(data.unrealized_pnl);
|
||||
}
|
||||
if(typeof data.available_trading_usdt !== "undefined" && data.available_trading_usdt !== null){
|
||||
latestAvailableUsdt = Number(data.available_trading_usdt);
|
||||
|
||||
Reference in New Issue
Block a user