顶栏实时盈亏只显示U;交易账户USDT/ETH多行展示
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -690,6 +690,14 @@ html[data-theme="light"] .theme-toggle-btn.is-active {
|
|||||||
white-space: nowrap;
|
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 {
|
.stat-strip-item--primary .label {
|
||||||
font-size: 0.76rem;
|
font-size: 0.76rem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ def trading_account_label(
|
|||||||
) -> str:
|
) -> str:
|
||||||
"""交易账户顶栏文案.
|
"""交易账户顶栏文案.
|
||||||
|
|
||||||
币本位:USDT / ETH / BTC(有余额才带上,不显示其它币种).
|
币本位:USDT / ETH / BTC 多行(有余额才带上,不显示其它币种).
|
||||||
其它模式:xx.xxU.
|
其它模式:xx.xxU.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
@@ -167,7 +167,8 @@ def trading_account_label(
|
|||||||
btc_txt = _fmt_coin_amount(btc, min_amt=1e-7)
|
btc_txt = _fmt_coin_amount(btc, min_amt=1e-7)
|
||||||
if btc_txt is not None:
|
if btc_txt is not None:
|
||||||
parts.append(f"{btc_txt} BTC")
|
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(
|
def total_funds_usdt(
|
||||||
|
|||||||
@@ -1093,25 +1093,27 @@ function paintRealtimePnl(v, unit, spotPx){
|
|||||||
}
|
}
|
||||||
const sign = n > 0 ? "+" : "";
|
const sign = n > 0 ? "+" : "";
|
||||||
let text;
|
let text;
|
||||||
|
let tone = n;
|
||||||
if (u === "ETH" || u === "BTC") {
|
if (u === "ETH" || u === "BTC") {
|
||||||
const abs = Math.abs(n).toFixed(8).replace(/\.?0+$/, "") || "0";
|
// 顶栏实时盈亏只显示 U(按指数/现货换算),不展示币数量
|
||||||
const coinTxt = `${n < 0 ? "-" : sign}${abs} ${u}`;
|
|
||||||
const px = Number(spotPx != null ? spotPx : lastRealtimePnlSpotPx);
|
const px = Number(spotPx != null ? spotPx : lastRealtimePnlSpotPx);
|
||||||
if (Number.isFinite(px) && px > 0) {
|
if (Number.isFinite(px) && px > 0) {
|
||||||
const uu = n * px;
|
const uu = n * px;
|
||||||
|
tone = uu;
|
||||||
const uAbs = Math.abs(uu).toFixed(2);
|
const uAbs = Math.abs(uu).toFixed(2);
|
||||||
const uSign = uu < 0 ? "-" : uu > 0 ? "+" : "";
|
const uSign = uu < 0 ? "-" : uu > 0 ? "+" : "";
|
||||||
text = `${coinTxt} / ${uSign}${uAbs}U`;
|
text = `${uSign}${uAbs}U`;
|
||||||
} else {
|
} else {
|
||||||
text = coinTxt;
|
text = "—";
|
||||||
|
tone = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
text = `${sign}${n.toFixed(2)}U`;
|
text = `${sign}${n.toFixed(2)}U`;
|
||||||
}
|
}
|
||||||
nodes.forEach((pnlEl) => {
|
nodes.forEach((pnlEl) => {
|
||||||
pnlEl.innerText = text;
|
pnlEl.innerText = text;
|
||||||
pnlEl.classList.toggle("pnl-pos", n > 0);
|
pnlEl.classList.toggle("pnl-pos", tone > 0);
|
||||||
pnlEl.classList.toggle("pnl-neg", n < 0);
|
pnlEl.classList.toggle("pnl-neg", tone < 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let lastRealtimePnl = null;
|
let lastRealtimePnl = null;
|
||||||
@@ -1160,25 +1162,21 @@ function paintRealtimePnlFromSnapshot(data){
|
|||||||
if (coinMode) {
|
if (coinMode) {
|
||||||
if (opt != null && !Number.isNaN(Number(opt))) {
|
if (opt != null && !Number.isNaN(Number(opt))) {
|
||||||
if (perp != null && Math.abs(Number(perp)) >= 0.005) {
|
if (perp != null && Math.abs(Number(perp)) >= 0.005) {
|
||||||
const optAbs = Math.abs(Number(opt)).toFixed(8).replace(/\.?0+$/, "") || "0";
|
// 顶栏只显示合计 U:永续 U + 期权币盈亏×指数
|
||||||
const optSign = Number(opt) > 0 ? "+" : (Number(opt) < 0 ? "-" : "");
|
let totalU = Number(perp);
|
||||||
const perpSign = Number(perp) > 0 ? "+" : "";
|
|
||||||
let optPart = `${optSign}${optAbs} ${underly}`;
|
|
||||||
if (Number.isFinite(spotPx) && spotPx > 0) {
|
if (Number.isFinite(spotPx) && spotPx > 0) {
|
||||||
const uu = Number(opt) * spotPx;
|
totalU += Number(opt) * spotPx;
|
||||||
const uAbs = Math.abs(uu).toFixed(2);
|
|
||||||
const uSign = uu < 0 ? "-" : uu > 0 ? "+" : "";
|
|
||||||
optPart += ` / ${uSign}${uAbs}U`;
|
|
||||||
}
|
}
|
||||||
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);
|
lastRealtimePnl = Number(opt);
|
||||||
lastRealtimePnlUnit = underly;
|
lastRealtimePnlUnit = underly;
|
||||||
lastRealtimePnlSpotPx = spotPx;
|
lastRealtimePnlSpotPx = spotPx;
|
||||||
document.querySelectorAll('[data-funds-field="realtime-pnl"]').forEach((pnlEl) => {
|
document.querySelectorAll('[data-funds-field="realtime-pnl"]').forEach((pnlEl) => {
|
||||||
pnlEl.innerText = text;
|
pnlEl.innerText = text;
|
||||||
const n = Number(opt) + Number(perp);
|
pnlEl.classList.toggle("pnl-pos", totalU > 0);
|
||||||
pnlEl.classList.toggle("pnl-pos", n > 0);
|
pnlEl.classList.toggle("pnl-neg", totalU < 0);
|
||||||
pnlEl.classList.toggle("pnl-neg", n < 0);
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1225,7 +1223,7 @@ function formatTradingAccountLabel(usdt, eth, btc, marginMode) {
|
|||||||
};
|
};
|
||||||
pushCoin(eth, "ETH");
|
pushCoin(eth, "ETH");
|
||||||
pushCoin(btc, "BTC");
|
pushCoin(btc, "BTC");
|
||||||
return parts.length ? parts.join(" / ") : "—";
|
return parts.length ? parts.join("\n") : "—";
|
||||||
}
|
}
|
||||||
|
|
||||||
function setFundsFieldText(field, text){
|
function setFundsFieldText(field, text){
|
||||||
|
|||||||
@@ -1574,25 +1574,27 @@ function paintRealtimePnl(v, unit, spotPx){
|
|||||||
}
|
}
|
||||||
const sign = n > 0 ? "+" : "";
|
const sign = n > 0 ? "+" : "";
|
||||||
let text;
|
let text;
|
||||||
|
let tone = n;
|
||||||
if (u === "ETH" || u === "BTC") {
|
if (u === "ETH" || u === "BTC") {
|
||||||
const abs = Math.abs(n).toFixed(8).replace(/\.?0+$/, "") || "0";
|
// 顶栏实时盈亏只显示 U(按指数/现货换算),不展示币数量
|
||||||
const coinTxt = `${n < 0 ? "-" : sign}${abs} ${u}`;
|
|
||||||
const px = Number(spotPx != null ? spotPx : lastRealtimePnlSpotPx);
|
const px = Number(spotPx != null ? spotPx : lastRealtimePnlSpotPx);
|
||||||
if (Number.isFinite(px) && px > 0) {
|
if (Number.isFinite(px) && px > 0) {
|
||||||
const uu = n * px;
|
const uu = n * px;
|
||||||
|
tone = uu;
|
||||||
const uAbs = Math.abs(uu).toFixed(2);
|
const uAbs = Math.abs(uu).toFixed(2);
|
||||||
const uSign = uu < 0 ? "-" : uu > 0 ? "+" : "";
|
const uSign = uu < 0 ? "-" : uu > 0 ? "+" : "";
|
||||||
text = `${coinTxt} / ${uSign}${uAbs}U`;
|
text = `${uSign}${uAbs}U`;
|
||||||
} else {
|
} else {
|
||||||
text = coinTxt;
|
text = "—";
|
||||||
|
tone = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
text = `${sign}${n.toFixed(2)}U`;
|
text = `${sign}${n.toFixed(2)}U`;
|
||||||
}
|
}
|
||||||
nodes.forEach((pnlEl) => {
|
nodes.forEach((pnlEl) => {
|
||||||
pnlEl.innerText = text;
|
pnlEl.innerText = text;
|
||||||
pnlEl.classList.toggle("pnl-pos", n > 0);
|
pnlEl.classList.toggle("pnl-pos", tone > 0);
|
||||||
pnlEl.classList.toggle("pnl-neg", n < 0);
|
pnlEl.classList.toggle("pnl-neg", tone < 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let lastRealtimePnl = null;
|
let lastRealtimePnl = null;
|
||||||
@@ -1642,25 +1644,21 @@ function paintRealtimePnlFromSnapshot(data){
|
|||||||
if (opt != null && !Number.isNaN(Number(opt))) {
|
if (opt != null && !Number.isNaN(Number(opt))) {
|
||||||
// 币本位期权盈亏单位为币,勿与永续 U 混加成「xxU」
|
// 币本位期权盈亏单位为币,勿与永续 U 混加成「xxU」
|
||||||
if (perp != null && Math.abs(Number(perp)) >= 0.005) {
|
if (perp != null && Math.abs(Number(perp)) >= 0.005) {
|
||||||
const optAbs = Math.abs(Number(opt)).toFixed(8).replace(/\.?0+$/, "") || "0";
|
// 顶栏只显示合计 U:永续 U + 期权币盈亏×指数
|
||||||
const optSign = Number(opt) > 0 ? "+" : (Number(opt) < 0 ? "-" : "");
|
let totalU = Number(perp);
|
||||||
const perpSign = Number(perp) > 0 ? "+" : "";
|
|
||||||
let optPart = `${optSign}${optAbs} ${underly}`;
|
|
||||||
if (Number.isFinite(spotPx) && spotPx > 0) {
|
if (Number.isFinite(spotPx) && spotPx > 0) {
|
||||||
const uu = Number(opt) * spotPx;
|
totalU += Number(opt) * spotPx;
|
||||||
const uAbs = Math.abs(uu).toFixed(2);
|
|
||||||
const uSign = uu < 0 ? "-" : uu > 0 ? "+" : "";
|
|
||||||
optPart += ` / ${uSign}${uAbs}U`;
|
|
||||||
}
|
}
|
||||||
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);
|
lastRealtimePnl = Number(opt);
|
||||||
lastRealtimePnlUnit = underly;
|
lastRealtimePnlUnit = underly;
|
||||||
lastRealtimePnlSpotPx = spotPx;
|
lastRealtimePnlSpotPx = spotPx;
|
||||||
document.querySelectorAll('[data-funds-field="realtime-pnl"]').forEach((pnlEl) => {
|
document.querySelectorAll('[data-funds-field="realtime-pnl"]').forEach((pnlEl) => {
|
||||||
pnlEl.innerText = text;
|
pnlEl.innerText = text;
|
||||||
const n = Number(opt) + Number(perp);
|
pnlEl.classList.toggle("pnl-pos", totalU > 0);
|
||||||
pnlEl.classList.toggle("pnl-pos", n > 0);
|
pnlEl.classList.toggle("pnl-neg", totalU < 0);
|
||||||
pnlEl.classList.toggle("pnl-neg", n < 0);
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1707,7 +1705,7 @@ function formatTradingAccountLabel(usdt, eth, btc, marginMode) {
|
|||||||
};
|
};
|
||||||
pushCoin(eth, "ETH");
|
pushCoin(eth, "ETH");
|
||||||
pushCoin(btc, "BTC");
|
pushCoin(btc, "BTC");
|
||||||
return parts.length ? parts.join(" / ") : "—";
|
return parts.length ? parts.join("\n") : "—";
|
||||||
}
|
}
|
||||||
|
|
||||||
function setFundsFieldText(field, text){
|
function setFundsFieldText(field, text){
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ class TestShowPerpFunds(unittest.TestCase):
|
|||||||
self.assertEqual(options_funding_label(None, 10.0), "—")
|
self.assertEqual(options_funding_label(None, 10.0), "—")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
trading_account_label(20.0, 0.01, 0.001, margin_mode="coin"),
|
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",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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, None, None, margin_mode="usdc"), "100.00U")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
trading_account_label(100, 0.2, 0.001, margin_mode="coin"),
|
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(
|
self.assertEqual(
|
||||||
trading_account_label(0.02, 0.0, None, margin_mode="coin"),
|
trading_account_label(0.02, 0.0, None, margin_mode="coin"),
|
||||||
@@ -54,7 +54,7 @@ class TestHeaderStatsLib(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
trading_account_label(12.5, 0.004321, None, margin_mode="coin"),
|
trading_account_label(12.5, 0.004321, None, margin_mode="coin"),
|
||||||
"12.50 USDT / 0.004321 ETH",
|
"12.50 USDT\n0.004321 ETH",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user