{"record":{"id":"e4dbd559ac1a45cf","repo":"HKUDS/Vibe-Trading","slug":"binance-usd-m-field-name-must-be-an-integer","errorCode":null,"errorMessage":"Binance USD-M field {name} must be an integer","messagePattern":"Binance USD-M field (.+?) must be an integer","errorType":"exception","errorClass":"UsdMObservationError","httpStatus":null,"severity":"error","filePath":"agent/src/trading/connectors/binance/usdm.py","lineNumber":338,"sourceCode":"    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,\n        \"account_endpoint\": \"/fapi/v2/account\",\n        \"position_endpoint\": \"/fapi/v3/positionRisk\",\n        \"observation_absolute_tolerance\": absolute_tolerance,\n        \"observation_relative_tolerance\": OBSERVATION_RELATIVE_TOLERANCE,\n    }\n    encoded = json.dumps(payload, sort_keys=True, separators=(\",\", \":\")).encode()\n    return hashlib.sha256(encoded).hexdigest()\n","sourceCodeStart":320,"sourceCodeEnd":355,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/trading/connectors/binance/usdm.py#L320-L355","documentation":"Raised by _integer when a field is numeric and non-negative but has a fractional part (number.is_integer() is False). Used for fields that must be whole numbers, such as counts, indices, or update timestamps passed through _join_positions. The {name} placeholder names the offending field.","triggerScenarios":"A field expected to be an integer holds e.g. 1.5 or '3.0' is fine but '2.7' fails; commonly a float-scaled value (price*qty) accidentally placed where a count/index was expected, or mock data using arbitrary floats.","commonSituations":"Fixtures using random floats for integer fields; upstream computing an integer field via floating division; API change adding decimal precision to a previously integral field; unit confusion (ticks vs contracts).","solutions":["Check the named field in the raw payload for fractional values","Fix the producer: compute integer fields with integer arithmetic (// or round) or fix the fixture","Convert legitimately float-typed integral values (e.g. '3.0') before passing if the source is string-float","Verify field mapping — a fractional value often means the wrong field is being read"],"exampleFix":"// before\n_integer(payload.get(\"count\"), \"count\")  # 2.5\n// after\n_integer(round(payload[\"count\"]), \"count\")  # or fix fixture to 2","handlingStrategy":"validation","validationCode":"def as_int(v) -> int | None:\n    try:\n        f = float(v)\n    except (TypeError, ValueError):\n        return None\n    return int(f) if f.is_integer() else None\n\npayload[\"count\"] = as_int(payload.get(\"count\")) or 0","typeGuard":"def is_integer_valued(value: Any) -> TypeGuard[int]:\n    try:\n        return float(value).is_integer()\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":"try:\n    obs = connector.read_account_observation(...)\nexcept UsdMObservationError as exc:\n    if \"must be an integer\" in str(exc):\n        logger.error(\"fractional value in integer field: %s\", exc)\n        fix_producer_and_refetch()\n    raise","preventionTips":["Use integer arithmetic (//, round) when producing count/index fields","Map float-typed integral strings ('3.0') before passing","Validate whole-number fields in fixtures"],"tags":["binance","usdm","integer-validation","type-validation","parsing"],"backgroundTag":"field-type-validation","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}