HKUDS/Vibe-Trading · critical · BinanceConfigError

Configured profile is live, but the resolved host '{host}' i

Error message

Configured profile is live, but the resolved host '{host}' is not the live host '{expected}'.

What it means

The live-profile counterpart of 1202: _assert_host raises when cfg.is_testnet is false and the parsed hostname of cfg.host does not match the canonical live host — USDM_LIVE_HOST (fapi.binance.com) for usdm market type, LIVE_HOST otherwise. It guarantees a live-labeled profile only ever talks to the approved production endpoint.

Source

Thrown at agent/src/trading/connectors/binance/sdk.py:764

def _assert_host(cfg: BinanceConfig) -> None:
    """Fail closed when the resolved host does not match the declared environment.

    The host is the authoritative discriminator: testnet keys cannot reach the
    live host. A live profile must resolve to ``api.binance.com``; a paper
    profile must resolve to the configured testnet host.
    """
    host = (urlparse(cfg.host).hostname or cfg.host or "").lower()
    if cfg.is_testnet:
        expected = (urlparse(cfg.testnet_host).hostname or cfg.testnet_host or "").lower()
        if host != expected:
            raise BinanceConfigError(
                f"Configured profile is paper, but the resolved host '{host}' is not the testnet host '{expected}'."
            )
        return
    expected_url = USDM_LIVE_HOST if cfg.market_type == "usdm" else LIVE_HOST
    expected = urlparse(expected_url).hostname or expected_url
    if host != expected:
        raise BinanceConfigError(
            f"Configured profile is live, but the resolved host '{host}' is not the live host '{expected}'."
        )


def _missing_fields(cfg: BinanceConfig) -> list[str]:
    missing = []
    if not cfg.api_key:
        missing.append("api_key")
    if not cfg.api_secret:
        missing.append("api_secret")
    return missing


def _public_config(cfg: BinanceConfig) -> dict[str, Any]:
    """Config snapshot with secrets redacted."""
    data = asdict(cfg)
    if data.get("api_secret"):
        data["api_secret"] = "***redacted***"

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Set cfg.host to exactly USDM_LIVE_HOST (usdm) or LIVE_HOST (spot) as appropriate for market_type
  2. Re-check market_type: a usdm config must use the fapi host, not the spot host
  3. Clear stale HOST env overrides when flipping the profile between paper and live
  4. Add a startup assertion comparing urlparse(host).hostname to the expected canonical host before trading

Example fix

# before
cfg = BinanceConfig(host="https://api.binance.com", market_type="usdm", is_testnet=False)

# after
cfg = BinanceConfig(host="https://fapi.binance.com", market_type="usdm", is_testnet=False)
Defensive patterns

Strategy: validation

Validate before calling

from urllib.parse import urlparse
if not cfg.is_testnet:
    expected = urlparse(USDM_LIVE_HOST if cfg.market_type == 'usdm' else LIVE_HOST).hostname
    actual = urlparse(cfg.host).hostname or cfg.host
    assert actual.lower() == expected.lower(), (actual, expected)

Type guard

def is_live_host_consistent(cfg, usdm_live_host: str, live_host: str) -> bool:
    if cfg.is_testnet:
        return True
    expected = urlparse(usdm_live_host if cfg.market_type == 'usdm' else live_host).hostname
    return (urlparse(cfg.host).hostname or cfg.host).lower() == expected.lower()

Try / catch

try:
    sdk.check_status(cfg)
except BinanceConfigError as exc:
    if 'not the live host' in str(exc):
        raise SystemExit(f'fix host for market_type={cfg.market_type}: {exc}')
    raise

Prevention

When it happens

Trigger: cfg.is_testnet=False with cfg.host set to the testnet host, a custom/proxy domain, an empty value, or a spot host while market_type is usdm (expected becomes USDM_LIVE_HOST). Any port/path/scheme in host that changes the parsed hostname also triggers it.

Common situations: Switching a profile from paper to live without updating host; market_type changed from spot to usdm while host still points at api.binance.com; proxy or regional mirror hostname in host; stale env var overriding host after a profile change.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/dcc3a9056438903f. Report an issue: GitHub.