币本位顶栏去掉期权资金/交易列,交易账户显示USDT/ETH/BTC
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -107,10 +107,39 @@ def options_funding_label(
|
||||
margin_mode: str | None = None,
|
||||
underly: str = "ETH",
|
||||
) -> str:
|
||||
"""期权侧顶栏文案.
|
||||
"""期权侧顶栏文案(仅 USDC 模式使用;币本位不展示期权资金/交易两列)."""
|
||||
if funding_usdc is None:
|
||||
return "—"
|
||||
try:
|
||||
return f"{float(funding_usdc):.2f} USDC"
|
||||
except (TypeError, ValueError):
|
||||
return "—"
|
||||
|
||||
USDC 模式:仅 USDC.
|
||||
币本位:USDT + 标的币(ETH/BTC).
|
||||
|
||||
def _fmt_coin_amount(v: float | None) -> str | None:
|
||||
if v is None:
|
||||
return None
|
||||
try:
|
||||
n = float(v)
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
if abs(n) < 1e-12:
|
||||
return None
|
||||
txt = f"{n:.6f}".rstrip("0").rstrip(".")
|
||||
return txt or None
|
||||
|
||||
|
||||
def trading_account_label(
|
||||
usdt: float | None,
|
||||
eth: float | None = None,
|
||||
btc: float | None = None,
|
||||
*,
|
||||
margin_mode: str | None = None,
|
||||
) -> str:
|
||||
"""交易账户顶栏文案.
|
||||
|
||||
币本位:USDT / ETH / BTC(有余额才带上,不显示其它币种).
|
||||
其它模式:xx.xxU.
|
||||
"""
|
||||
try:
|
||||
from lib.options.options_margin_mode_lib import normalize_options_margin_mode
|
||||
@@ -118,29 +147,26 @@ def options_funding_label(
|
||||
mode = normalize_options_margin_mode(margin_mode)
|
||||
except Exception:
|
||||
mode = str(margin_mode or "usdc").strip().lower() or "usdc"
|
||||
if mode == "coin":
|
||||
parts: list[str] = []
|
||||
if funding_usdt is not None:
|
||||
try:
|
||||
parts.append(f"{float(funding_usdt):.2f} USDT")
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
coin = funding_eth
|
||||
ccy = (underly or "ETH").strip().upper() or "ETH"
|
||||
if coin is not None:
|
||||
try:
|
||||
n = float(coin)
|
||||
txt = f"{n:.6f}".rstrip("0").rstrip(".")
|
||||
parts.append(f"{txt or '0'} {ccy}")
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
return " / ".join(parts) if parts else "—"
|
||||
if funding_usdc is None:
|
||||
return "—"
|
||||
try:
|
||||
return f"{float(funding_usdc):.2f} USDC"
|
||||
except (TypeError, ValueError):
|
||||
return "—"
|
||||
if mode != "coin":
|
||||
if usdt is None:
|
||||
return "—"
|
||||
try:
|
||||
return f"{float(usdt):.2f}U"
|
||||
except (TypeError, ValueError):
|
||||
return "—"
|
||||
parts: list[str] = []
|
||||
if usdt is not None:
|
||||
try:
|
||||
parts.append(f"{float(usdt):.2f} USDT")
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
eth_txt = _fmt_coin_amount(eth)
|
||||
if eth_txt is not None:
|
||||
parts.append(f"{eth_txt} ETH")
|
||||
btc_txt = _fmt_coin_amount(btc)
|
||||
if btc_txt is not None:
|
||||
parts.append(f"{btc_txt} BTC")
|
||||
return " / ".join(parts) if parts else "—"
|
||||
|
||||
|
||||
def total_funds_usdt(
|
||||
|
||||
Reference in New Issue
Block a user