From 467f4f092fd0f2cedf98a6754595010ca32b27cf Mon Sep 17 00:00:00 2001 From: dekun Date: Thu, 20 Aug 2026 18:05:42 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B6=E6=A0=8F=E5=AE=9E=E6=97=B6=E7=9B=88?= =?UTF-8?q?=E4=BA=8F=E5=8F=AA=E6=98=BE=E7=A4=BAU=EF=BC=9B=E4=BA=A4?= =?UTF-8?q?=E6=98=93=E8=B4=A6=E6=88=B7USDT/ETH=E5=A4=9A=E8=A1=8C=E5=B1=95?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- lib/common/static/instance_theme.css | 8 +++++ lib/instance/instance_embed_context_lib.py | 5 +-- .../templates/embed_boot_scripts.html | 36 +++++++++---------- lib/instance/templates/index.html | 36 +++++++++---------- tests/test_instance_display_env_settings.py | 2 +- tests/test_instance_header_stats_lib.py | 4 +-- 6 files changed, 48 insertions(+), 43 deletions(-) diff --git a/lib/common/static/instance_theme.css b/lib/common/static/instance_theme.css index 59d0413..aabd5a6 100644 --- a/lib/common/static/instance_theme.css +++ b/lib/common/static/instance_theme.css @@ -690,6 +690,14 @@ html[data-theme="light"] .theme-toggle-btn.is-active { white-space: nowrap; } +#current-capital, +.stat-strip-item [data-funds-field="current-capital"], +.inst-phone-chip [data-funds-field="current-capital"] { + white-space: pre-line; + line-height: 1.2; + font-size: 0.82rem; +} + .stat-strip-item--primary .label { font-size: 0.76rem; } diff --git a/lib/instance/instance_embed_context_lib.py b/lib/instance/instance_embed_context_lib.py index fdcac17..17bd25a 100644 --- a/lib/instance/instance_embed_context_lib.py +++ b/lib/instance/instance_embed_context_lib.py @@ -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( diff --git a/lib/instance/templates/embed_boot_scripts.html b/lib/instance/templates/embed_boot_scripts.html index 899e8c0..4821929 100644 --- a/lib/instance/templates/embed_boot_scripts.html +++ b/lib/instance/templates/embed_boot_scripts.html @@ -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){ diff --git a/lib/instance/templates/index.html b/lib/instance/templates/index.html index a24a38e..507be0e 100644 --- a/lib/instance/templates/index.html +++ b/lib/instance/templates/index.html @@ -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){ diff --git a/tests/test_instance_display_env_settings.py b/tests/test_instance_display_env_settings.py index eb794ea..5a24f42 100644 --- a/tests/test_instance_display_env_settings.py +++ b/tests/test_instance_display_env_settings.py @@ -159,7 +159,7 @@ class TestShowPerpFunds(unittest.TestCase): self.assertEqual(options_funding_label(None, 10.0), "—") self.assertEqual( trading_account_label(20.0, 0.01, 0.001, margin_mode="coin"), - "20.00 USDT / 0.01 ETH / 0.001 BTC", + "20.00 USDT\n0.01 ETH\n0.001 BTC", ) diff --git a/tests/test_instance_header_stats_lib.py b/tests/test_instance_header_stats_lib.py index 0c10150..db06fe9 100644 --- a/tests/test_instance_header_stats_lib.py +++ b/tests/test_instance_header_stats_lib.py @@ -46,7 +46,7 @@ class TestHeaderStatsLib(unittest.TestCase): self.assertEqual(trading_account_label(100, None, None, margin_mode="usdc"), "100.00U") self.assertEqual( trading_account_label(100, 0.2, 0.001, margin_mode="coin"), - "100.00 USDT / 0.2 ETH / 0.001 BTC", + "100.00 USDT\n0.2 ETH\n0.001 BTC", ) self.assertEqual( trading_account_label(0.02, 0.0, None, margin_mode="coin"), @@ -54,7 +54,7 @@ class TestHeaderStatsLib(unittest.TestCase): ) self.assertEqual( trading_account_label(12.5, 0.004321, None, margin_mode="coin"), - "12.50 USDT / 0.004321 ETH", + "12.50 USDT\n0.004321 ETH", )