{"record":{"id":"5318a5b6bcbeb725","repo":"HKUDS/Vibe-Trading","slug":"binance-usd-m-field-name-must-be-positive","errorCode":null,"errorMessage":"Binance USD-M field {name} must be positive","messagePattern":"Binance USD-M field (.+?) must be positive","errorType":"exception","errorClass":"UsdMObservationError","httpStatus":null,"severity":"error","filePath":"agent/src/trading/connectors/binance/usdm.py","lineNumber":329,"sourceCode":"        raise UsdMObservationError(\"Binance USD-M supports canonical */USDT symbols only\")\n    return f\"{symbol[:-4]}-USDT-PERP\"\n\n\ndef _number(\n    value: Any,\n    name: str,\n    *,\n    non_negative: bool = False,\n    positive: bool = False,\n) -> float:\n    try:\n        number = float(value)\n    except (TypeError, ValueError) as exc:\n        raise UsdMObservationError(f\"Binance USD-M field {name} must be numeric\") from exc\n    if not math.isfinite(number):\n        raise UsdMObservationError(f\"Binance USD-M field {name} must be finite\")\n    if positive and number <= 0:\n        raise UsdMObservationError(f\"Binance USD-M field {name} must be positive\")\n    if non_negative and number < 0:\n        raise UsdMObservationError(f\"Binance USD-M field {name} must be non-negative\")\n    return number\n\n\ndef _integer(value: Any, name: str) -> int:\n    number = _number(value, name, non_negative=True)\n    if not number.is_integer():\n        raise UsdMObservationError(f\"Binance USD-M field {name} must be an integer\")\n    return int(number)\n\n\ndef _configuration_hash(source_profile: str, host: str, absolute_tolerance: float) -> str:\n    payload = {\n        \"schema_version\": SCHEMA_VERSION,\n        \"source_profile\": source_profile,\n        \"market_type\": \"usdm\",\n        \"host\": host,","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/trading/connectors/binance/usdm.py#L311-L347","documentation":"Raised by _number when a field is numeric and finite but <= 0 while positive=True was requested. This is used for quantities that must be strictly positive (e.g. leverage, quantities used as divisors). The {name} placeholder names the offending field so the caller can locate it in the payload.","triggerScenarios":"A field such as leverage or a size parameter is 0 or negative in the payload; e.g. leverage='0' on a symbol row, or a computed price/size collapsing to 0 due to an upstream bug.","commonSituations":"Exchange returning 0 leverage or 0 values for newly listed symbols before initialization; mocks defaulting numbers to 0; upstream rounding wiping out tiny positive values to 0; sign errors producing negative amounts.","solutions":["Check the field named in the message in the raw payload; confirm it should be > 0","For genuinely unset fields, fetch them from the correct endpoint (e.g. real leverage from positionRisk/leverage) instead of a default 0","Fix fixtures to use positive values","Guard upstream computations against zero before passing results in"],"exampleFix":"// before\n_number(row.get(\"leverage\"), \"leverage\", positive=True)  # leverage == 0\n// after\n_number(row.get(\"leverage\") or 1, \"leverage\", positive=True)","handlingStrategy":"validation","validationCode":"def positive_or_none(row: dict, key: str) -> float | None:\n    try:\n        v = float(row.get(key))\n    except (TypeError, ValueError):\n        return None\n    return v if v > 0 else None\n\nlev = positive_or_none(row, \"leverage\") or fetch_leverage(symbol)","typeGuard":null,"tryCatchPattern":"try:\n    obs = connector.read_account_observation(...)\nexcept UsdMObservationError as exc:\n    if \"must be positive\" in str(exc):\n        logger.error(\"non-positive %s; refreshing symbol config\", exc)\n        refresh_symbol_meta()\n    raise","preventionTips":["Never default must-be-positive fields to 0","Fetch leverage/sizes from authoritative endpoints","Assert invariants on computed sizes before passing them in"],"tags":["binance","usdm","positive-value","range-validation","leverage"],"backgroundTag":"out-of-range-value-validation","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}