币本位实时盈亏/期权浮盈按ETH展示,避免两位小数抹成0.00U
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1075,7 +1075,7 @@ function refreshOrderDefaults(){
|
||||
}).catch(()=>{});
|
||||
}
|
||||
|
||||
function paintRealtimePnl(v){
|
||||
function paintRealtimePnl(v, unit){
|
||||
const nodes = document.querySelectorAll('[data-funds-field="realtime-pnl"]');
|
||||
if(!nodes.length) return;
|
||||
if(v === null || v === undefined || Number.isNaN(Number(v))){
|
||||
@@ -1086,8 +1086,16 @@ function paintRealtimePnl(v){
|
||||
return;
|
||||
}
|
||||
const n = Number(v);
|
||||
const u = String(unit || lastRealtimePnlUnit || "U").toUpperCase() || "U";
|
||||
lastRealtimePnlUnit = u;
|
||||
const sign = n > 0 ? "+" : "";
|
||||
const text = `${sign}${n.toFixed(2)}U`;
|
||||
let text;
|
||||
if (u === "ETH" || u === "BTC") {
|
||||
const abs = Math.abs(n).toFixed(8).replace(/\.?0+$/, "") || "0";
|
||||
text = `${n < 0 ? "-" : sign}${abs}${u}`;
|
||||
} else {
|
||||
text = `${sign}${n.toFixed(2)}U`;
|
||||
}
|
||||
nodes.forEach((pnlEl) => {
|
||||
pnlEl.innerText = text;
|
||||
pnlEl.classList.toggle("pnl-pos", n > 0);
|
||||
@@ -1095,14 +1103,16 @@ function paintRealtimePnl(v){
|
||||
});
|
||||
}
|
||||
let lastRealtimePnl = null;
|
||||
function updateRealtimePnl(v){
|
||||
let lastRealtimePnlUnit = "U";
|
||||
function updateRealtimePnl(v, unit){
|
||||
if(v != null && !Number.isNaN(Number(v))){
|
||||
lastRealtimePnl = Number(v);
|
||||
paintRealtimePnl(v);
|
||||
if (unit) lastRealtimePnlUnit = String(unit).toUpperCase();
|
||||
paintRealtimePnl(v, lastRealtimePnlUnit);
|
||||
return;
|
||||
}
|
||||
if(lastRealtimePnl != null) return;
|
||||
paintRealtimePnl(v);
|
||||
paintRealtimePnl(v, lastRealtimePnlUnit);
|
||||
}
|
||||
function sumOrdersFloatPnl(orders){
|
||||
if(!orders || !orders.length) return null;
|
||||
@@ -1130,9 +1140,31 @@ function paintRealtimePnlFromSnapshot(data){
|
||||
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);
|
||||
const opt = data.options_unrealized_pnl;
|
||||
const coinMode = String(data.options_margin_mode || "").toLowerCase() === "coin";
|
||||
const underly = String(data.options_underly || "ETH").toUpperCase() || "ETH";
|
||||
if (coinMode && opt != null && !Number.isNaN(Number(opt))) {
|
||||
if (perp != null && Math.abs(Number(perp)) >= 0.005) {
|
||||
const optAbs = Math.abs(Number(opt)).toFixed(8).replace(/\.?0+$/, "") || "0";
|
||||
const optSign = Number(opt) > 0 ? "+" : (Number(opt) < 0 ? "-" : "");
|
||||
const perpSign = Number(perp) > 0 ? "+" : "";
|
||||
const text = `${perpSign}${Number(perp).toFixed(2)}U / ${optSign}${optAbs}${underly}`;
|
||||
lastRealtimePnl = Number(opt);
|
||||
lastRealtimePnlUnit = underly;
|
||||
document.querySelectorAll('[data-funds-field="realtime-pnl"]').forEach((pnlEl) => {
|
||||
pnlEl.innerText = text;
|
||||
const n = Number(opt) + Number(perp);
|
||||
pnlEl.classList.toggle("pnl-pos", n > 0);
|
||||
pnlEl.classList.toggle("pnl-neg", n < 0);
|
||||
});
|
||||
return;
|
||||
}
|
||||
paintRealtimePnl(opt, underly);
|
||||
return;
|
||||
}
|
||||
const combined = combineRealtimeFloatPnl(perp, opt);
|
||||
if(combined !== null || perp !== null || opt != null){
|
||||
paintRealtimePnl(combined, "U");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user