{"record":{"id":"dcc3a9056438903f","repo":"HKUDS/Vibe-Trading","slug":"configured-profile-is-live-but-the-resolved-host","errorCode":null,"errorMessage":"Configured profile is live, but the resolved host '{host}' is not the live host '{expected}'.","messagePattern":"Configured profile is live, but the resolved host '(.+?)' is not the live host '(.+?)'\\.","errorType":"exception","errorClass":"BinanceConfigError","httpStatus":null,"severity":"critical","filePath":"agent/src/trading/connectors/binance/sdk.py","lineNumber":764,"sourceCode":"def _assert_host(cfg: BinanceConfig) -> None:\n    \"\"\"Fail closed when the resolved host does not match the declared environment.\n\n    The host is the authoritative discriminator: testnet keys cannot reach the\n    live host. A live profile must resolve to ``api.binance.com``; a paper\n    profile must resolve to the configured testnet host.\n    \"\"\"\n    host = (urlparse(cfg.host).hostname or cfg.host or \"\").lower()\n    if cfg.is_testnet:\n        expected = (urlparse(cfg.testnet_host).hostname or cfg.testnet_host or \"\").lower()\n        if host != expected:\n            raise BinanceConfigError(\n                f\"Configured profile is paper, but the resolved host '{host}' is not the testnet host '{expected}'.\"\n            )\n        return\n    expected_url = USDM_LIVE_HOST if cfg.market_type == \"usdm\" else LIVE_HOST\n    expected = urlparse(expected_url).hostname or expected_url\n    if host != expected:\n        raise BinanceConfigError(\n            f\"Configured profile is live, but the resolved host '{host}' is not the live host '{expected}'.\"\n        )\n\n\ndef _missing_fields(cfg: BinanceConfig) -> list[str]:\n    missing = []\n    if not cfg.api_key:\n        missing.append(\"api_key\")\n    if not cfg.api_secret:\n        missing.append(\"api_secret\")\n    return missing\n\n\ndef _public_config(cfg: BinanceConfig) -> dict[str, Any]:\n    \"\"\"Config snapshot with secrets redacted.\"\"\"\n    data = asdict(cfg)\n    if data.get(\"api_secret\"):\n        data[\"api_secret\"] = \"***redacted***\"","sourceCodeStart":746,"sourceCodeEnd":782,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/trading/connectors/binance/sdk.py#L746-L782","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set cfg.host to exactly USDM_LIVE_HOST (usdm) or LIVE_HOST (spot) as appropriate for market_type","Re-check market_type: a usdm config must use the fapi host, not the spot host","Clear stale HOST env overrides when flipping the profile between paper and live","Add a startup assertion comparing urlparse(host).hostname to the expected canonical host before trading"],"exampleFix":"# before\ncfg = BinanceConfig(host=\"https://api.binance.com\", market_type=\"usdm\", is_testnet=False)\n\n# after\ncfg = BinanceConfig(host=\"https://fapi.binance.com\", market_type=\"usdm\", is_testnet=False)","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse\nif not cfg.is_testnet:\n    expected = urlparse(USDM_LIVE_HOST if cfg.market_type == 'usdm' else LIVE_HOST).hostname\n    actual = urlparse(cfg.host).hostname or cfg.host\n    assert actual.lower() == expected.lower(), (actual, expected)","typeGuard":"def is_live_host_consistent(cfg, usdm_live_host: str, live_host: str) -> bool:\n    if cfg.is_testnet:\n        return True\n    expected = urlparse(usdm_live_host if cfg.market_type == 'usdm' else live_host).hostname\n    return (urlparse(cfg.host).hostname or cfg.host).lower() == expected.lower()","tryCatchPattern":"try:\n    sdk.check_status(cfg)\nexcept BinanceConfigError as exc:\n    if 'not the live host' in str(exc):\n        raise SystemExit(f'fix host for market_type={cfg.market_type}: {exc}')\n    raise","preventionTips":["Map market_type to the correct canonical host (usdm=>fapi, spot=>api) in one helper","When flipping profile paper<->live, update host in the same change","Assert hostname equality in CI config validation"],"tags":["binance","config-validation","live-trading","host-mismatch","fail-closed"],"backgroundTag":"environment-host-mismatch","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}