PINK Phase 5+6 (G6+G7): live VST gate + BLUE fence

bingx_user_stream.py: fix account_snapshot() for VST v3 balance
  (v3 returns list, not dict; extract first element)

test_pink_account_ws_g6.py (Gate G6 basic):
  I7: poll snapshot wallet_balance > 0 (PASS - live VST)
  I1-I5: seed + E-fact -> k_capital, available=E, reconcile OK/WARN,
    FILL_SETTLED folds correctly, delta=net_drift (PASS - live VST)
  I6: WS connects + gap-backfill delivers ACCOUNT_UPDATE source=poll
    (PASS - live VST)

test_alpha_blue_untouched_g7.py (Gate G7):
  mainnet hard-disabled, no BLUE imports, git diff clean

3/3 live + 131 offline = all gates green.
This commit is contained in:
Codex
2026-06-01 22:35:27 +02:00
parent 577392be8c
commit 23619e603a
2 changed files with 173 additions and 4 deletions

View File

@@ -174,11 +174,17 @@ class BingxUserStream:
bal = await self._http.signed_get( # type: ignore[attr-defined]
"/openApi/swap/v3/user/balance", {}
)
data = bal if isinstance(bal, dict) else {}
wallet = _safe_float(data.get("balance") or data.get("totalWalletBalance") or data.get("availableMargin"))
# v3 returns a list; v2 returns {"balance": {...}}
if isinstance(bal, list):
data = bal[0] if bal else {}
elif isinstance(bal, dict):
data = bal.get("balance") if isinstance(bal.get("balance"), dict) else bal
else:
data = {}
wallet = _safe_float(data.get("equity") or data.get("balance") or data.get("totalWalletBalance"))
avail = _safe_float(data.get("availableMargin") or data.get("availableBalance"))
used = _safe_float(data.get("usedMargin") or data.get("totalInitialMargin"))
maint = _safe_float(data.get("maintenanceMargin") or data.get("totalMaintMargin"))
used = _safe_float(data.get("usedMargin") or data.get("frozenMargin") or data.get("totalInitialMargin"))
maint = _safe_float(data.get("maintenanceMargin") or data.get("totalMaintMargin") or 0.0)
except Exception as exc: # noqa: BLE001
log.warning("bingx_user_stream: balance REST failed: %s", exc)