diff --git a/lib/hub/hub_bridge_register.py b/lib/hub/hub_bridge_register.py index fa27315..267fdcd 100644 --- a/lib/hub/hub_bridge_register.py +++ b/lib/hub/hub_bridge_register.py @@ -148,13 +148,17 @@ def _enrich_hub_protocol(snap: dict[str, Any], *, app_module: Any) -> dict[str, except (TypeError, ValueError): return None - # 账户资金口径:优先 USDT 资+交;都空则回退 USDC(≈U) - equity_parts = [_f(trading_usdt), _f(funding_usdt)] - if all(x is None for x in equity_parts): - equity_parts = [_f(trading_usdc), _f(funding_usdc)] - known = [x for x in equity_parts if x is not None] - equity_usdt = round(sum(known), 4) if known else None + # 账户可用余额:优先 USDT 资+交;都空则回退 USDC(≈U) + cash_parts = [_f(trading_usdt), _f(funding_usdt)] + if all(x is None for x in cash_parts): + cash_parts = [_f(trading_usdc), _f(funding_usdc)] + cash_known = [x for x in cash_parts if x is not None] + cash_usdt = round(sum(cash_known), 4) if cash_known else None premium_usdt = round(premium_total_usdt, 4) if has_premium else (0.0 if not slim_pos else None) + # 占比分母 = 当前余额 + 已付权利金(权利金已从余额扣出,需加回才是完整账户资金) + equity_usdt = None + if cash_usdt is not None or premium_usdt is not None: + equity_usdt = round(float(cash_usdt or 0.0) + float(premium_usdt or 0.0), 4) ratio_pct = None if premium_usdt is not None and equity_usdt is not None and equity_usdt > 1e-9: ratio_pct = round(float(premium_usdt) / float(equity_usdt) * 100.0, 2) @@ -164,6 +168,7 @@ def _enrich_hub_protocol(snap: dict[str, Any], *, app_module: Any) -> dict[str, } out["premium"] = { "paid_usdt": premium_usdt, + "cash_usdt": cash_usdt, "equity_usdt": equity_usdt, "ratio_pct": ratio_pct, }