顶栏实时盈亏只显示U;交易账户USDT/ETH多行展示

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-20 18:05:42 +08:00
parent 8b5080bdda
commit 467f4f092f
6 changed files with 48 additions and 43 deletions
+3 -2
View File
@@ -139,7 +139,7 @@ def trading_account_label(
) -> str:
"""交易账户顶栏文案.
币本位:USDT / ETH / BTC(有余额才带上,不显示其它币种).
币本位:USDT / ETH / BTC 多行(有余额才带上,不显示其它币种).
其它模式:xx.xxU.
"""
try:
@@ -167,7 +167,8 @@ def trading_account_label(
btc_txt = _fmt_coin_amount(btc, min_amt=1e-7)
if btc_txt is not None:
parts.append(f"{btc_txt} BTC")
return " / ".join(parts) if parts else ""
# 顶栏多行:USDT / ETH 各占一行
return "\n".join(parts) if parts else ""
def total_funds_usdt(
+17 -19
View File
@@ -1093,25 +1093,27 @@ function paintRealtimePnl(v, unit, spotPx){
}
const sign = n > 0 ? "+" : "";
let text;
let tone = n;
if (u === "ETH" || u === "BTC") {
const abs = Math.abs(n).toFixed(8).replace(/\.?0+$/, "") || "0";
const coinTxt = `${n < 0 ? "-" : sign}${abs} ${u}`;
// 顶栏实时盈亏只显示 U(按指数/现货换算),不展示币数量
const px = Number(spotPx != null ? spotPx : lastRealtimePnlSpotPx);
if (Number.isFinite(px) && px > 0) {
const uu = n * px;
tone = uu;
const uAbs = Math.abs(uu).toFixed(2);
const uSign = uu < 0 ? "-" : uu > 0 ? "+" : "";
text = `${coinTxt} / ${uSign}${uAbs}U`;
text = `${uSign}${uAbs}U`;
} else {
text = coinTxt;
text = "—";
tone = 0;
}
} else {
text = `${sign}${n.toFixed(2)}U`;
}
nodes.forEach((pnlEl) => {
pnlEl.innerText = text;
pnlEl.classList.toggle("pnl-pos", n > 0);
pnlEl.classList.toggle("pnl-neg", n < 0);
pnlEl.classList.toggle("pnl-pos", tone > 0);
pnlEl.classList.toggle("pnl-neg", tone < 0);
});
}
let lastRealtimePnl = null;
@@ -1160,25 +1162,21 @@ function paintRealtimePnlFromSnapshot(data){
if (coinMode) {
if (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 ? "+" : "";
let optPart = `${optSign}${optAbs} ${underly}`;
// 顶栏只显示合计 U:永续 U + 期权币盈亏×指数
let totalU = Number(perp);
if (Number.isFinite(spotPx) && spotPx > 0) {
const uu = Number(opt) * spotPx;
const uAbs = Math.abs(uu).toFixed(2);
const uSign = uu < 0 ? "-" : uu > 0 ? "+" : "";
optPart += ` / ${uSign}${uAbs}U`;
totalU += Number(opt) * spotPx;
}
const text = `${perpSign}${Number(perp).toFixed(2)}U / ${optPart}`;
const uAbs = Math.abs(totalU).toFixed(2);
const uSign = totalU < 0 ? "-" : totalU > 0 ? "+" : "";
const text = `${uSign}${uAbs}U`;
lastRealtimePnl = Number(opt);
lastRealtimePnlUnit = underly;
lastRealtimePnlSpotPx = spotPx;
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);
pnlEl.classList.toggle("pnl-pos", totalU > 0);
pnlEl.classList.toggle("pnl-neg", totalU < 0);
});
return;
}
@@ -1225,7 +1223,7 @@ function formatTradingAccountLabel(usdt, eth, btc, marginMode) {
};
pushCoin(eth, "ETH");
pushCoin(btc, "BTC");
return parts.length ? parts.join(" / ") : "—";
return parts.length ? parts.join("\n") : "—";
}
function setFundsFieldText(field, text){
+17 -19
View File
@@ -1574,25 +1574,27 @@ function paintRealtimePnl(v, unit, spotPx){
}
const sign = n > 0 ? "+" : "";
let text;
let tone = n;
if (u === "ETH" || u === "BTC") {
const abs = Math.abs(n).toFixed(8).replace(/\.?0+$/, "") || "0";
const coinTxt = `${n < 0 ? "-" : sign}${abs} ${u}`;
// 顶栏实时盈亏只显示 U(按指数/现货换算),不展示币数量
const px = Number(spotPx != null ? spotPx : lastRealtimePnlSpotPx);
if (Number.isFinite(px) && px > 0) {
const uu = n * px;
tone = uu;
const uAbs = Math.abs(uu).toFixed(2);
const uSign = uu < 0 ? "-" : uu > 0 ? "+" : "";
text = `${coinTxt} / ${uSign}${uAbs}U`;
text = `${uSign}${uAbs}U`;
} else {
text = coinTxt;
text = "—";
tone = 0;
}
} else {
text = `${sign}${n.toFixed(2)}U`;
}
nodes.forEach((pnlEl) => {
pnlEl.innerText = text;
pnlEl.classList.toggle("pnl-pos", n > 0);
pnlEl.classList.toggle("pnl-neg", n < 0);
pnlEl.classList.toggle("pnl-pos", tone > 0);
pnlEl.classList.toggle("pnl-neg", tone < 0);
});
}
let lastRealtimePnl = null;
@@ -1642,25 +1644,21 @@ function paintRealtimePnlFromSnapshot(data){
if (opt != null && !Number.isNaN(Number(opt))) {
// 币本位期权盈亏单位为币,勿与永续 U 混加成「xxU」
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 ? "+" : "";
let optPart = `${optSign}${optAbs} ${underly}`;
// 顶栏只显示合计 U:永续 U + 期权币盈亏×指数
let totalU = Number(perp);
if (Number.isFinite(spotPx) && spotPx > 0) {
const uu = Number(opt) * spotPx;
const uAbs = Math.abs(uu).toFixed(2);
const uSign = uu < 0 ? "-" : uu > 0 ? "+" : "";
optPart += ` / ${uSign}${uAbs}U`;
totalU += Number(opt) * spotPx;
}
const text = `${perpSign}${Number(perp).toFixed(2)}U / ${optPart}`;
const uAbs = Math.abs(totalU).toFixed(2);
const uSign = totalU < 0 ? "-" : totalU > 0 ? "+" : "";
const text = `${uSign}${uAbs}U`;
lastRealtimePnl = Number(opt);
lastRealtimePnlUnit = underly;
lastRealtimePnlSpotPx = spotPx;
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);
pnlEl.classList.toggle("pnl-pos", totalU > 0);
pnlEl.classList.toggle("pnl-neg", totalU < 0);
});
return;
}
@@ -1707,7 +1705,7 @@ function formatTradingAccountLabel(usdt, eth, btc, marginMode) {
};
pushCoin(eth, "ETH");
pushCoin(btc, "BTC");
return parts.length ? parts.join(" / ") : "—";
return parts.length ? parts.join("\n") : "—";
}
function setFundsFieldText(field, text){