资金占比分母改为余额加权利金,避免已付权利金被漏计。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-02 16:18:16 +08:00
parent bb6e9e9041
commit 3577a4d2fd
+11 -6
View File
@@ -148,13 +148,17 @@ def _enrich_hub_protocol(snap: dict[str, Any], *, app_module: Any) -> dict[str,
except (TypeError, ValueError): except (TypeError, ValueError):
return None return None
# 账户资金口径:优先 USDT 资+交;都空则回退 USDC(≈U) # 账户可用余额:优先 USDT 资+交;都空则回退 USDC(≈U)
equity_parts = [_f(trading_usdt), _f(funding_usdt)] cash_parts = [_f(trading_usdt), _f(funding_usdt)]
if all(x is None for x in equity_parts): if all(x is None for x in cash_parts):
equity_parts = [_f(trading_usdc), _f(funding_usdc)] cash_parts = [_f(trading_usdc), _f(funding_usdc)]
known = [x for x in equity_parts if x is not None] cash_known = [x for x in cash_parts if x is not None]
equity_usdt = round(sum(known), 4) if known else 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) 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 ratio_pct = None
if premium_usdt is not None and equity_usdt is not None and equity_usdt > 1e-9: 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) 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"] = { out["premium"] = {
"paid_usdt": premium_usdt, "paid_usdt": premium_usdt,
"cash_usdt": cash_usdt,
"equity_usdt": equity_usdt, "equity_usdt": equity_usdt,
"ratio_pct": ratio_pct, "ratio_pct": ratio_pct,
} }