{"record":{"id":"aad26c6591640e49","repo":"nautechsystems/nautilus_trader","slug":"binance-field-timestamp-is-outside-the-unixnanos","errorCode":null,"errorMessage":"Binance {field} timestamp is outside the UnixNanos range: {value}","messagePattern":"Binance (.+?) timestamp is outside the UnixNanos range: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/common/parse.rs","lineNumber":92,"sourceCode":"\npub(crate) fn parse_millis(value: i64, field: &str) -> anyhow::Result<UnixNanos> {\n    parse_timestamp(value, UnixNanos::from_millis_checked(value), field)\n}\n\npub(crate) fn parse_micros(value: i64, field: &str) -> anyhow::Result<UnixNanos> {\n    parse_timestamp(value, UnixNanos::from_micros_checked(value), field)\n}\n\nfn parse_timestamp(\n    value: i64,\n    timestamp: Option<UnixNanos>,\n    field: &str,\n) -> anyhow::Result<UnixNanos> {\n    timestamp.ok_or_else(|| {\n        if value < 0 {\n            anyhow::anyhow!(\"invalid negative Binance {field} timestamp: {value}\")\n        } else {\n            anyhow::anyhow!(\"Binance {field} timestamp is outside the UnixNanos range: {value}\")\n        }\n    })\n}\n\npub(crate) fn parse_millis_or_init(value: i64, field: &str, ts_init: UnixNanos) -> UnixNanos {\n    timestamp_or_init(parse_millis(value, field), ts_init)\n}\n\npub(crate) fn parse_micros_or_init(value: i64, field: &str, ts_init: UnixNanos) -> UnixNanos {\n    timestamp_or_init(parse_micros(value, field), ts_init)\n}\n\nfn timestamp_or_init(timestamp: anyhow::Result<UnixNanos>, ts_init: UnixNanos) -> UnixNanos {\n    match timestamp {\n        Ok(timestamp) => timestamp,\n        Err(e) => {\n            log::warn!(\"{e}; using initialization timestamp\");\n            ts_init","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/common/parse.rs#L74-L110","documentation":"A Binance timestamp parses to a value that, once scaled from milliseconds/microseconds to nanoseconds, falls outside the UnixNanos representable range (i64 nanoseconds since epoch). The value is non-negative but absurdly large, so the checked constructor returns None and this error reports the overflow.","triggerScenarios":"A millis/micros field containing a garbage-huge number, or a value in the wrong unit (e.g. nanoseconds fed where millis are expected) so the x1e6/x1e3 scaling overflows; corrupted or tampered payloads.","commonSituations":"Unit confusion when mapping fields from Binance's mixed ms/us APIs; corrupted captures; a proxy/gateway mangling numeric fields; clock-source bugs producing nonsense values.","solutions":["Inspect the raw value printed in the message and compare with the expected unit for that field (Binance uses ms for REST, us for some stream payloads)","Verify the data path - captures, proxies, or transformations between Binance and the adapter that could alter numbers","If the field is legitimately huge garbage from upstream, report it; do not clamp silently"],"exampleFix":"// before\nlet ts = parse_millis(value, \"workingTime\")?; // value actually microseconds\n\n// after\nlet ts = parse_micros(value, \"workingTime\")?; // match the field's real unit","handlingStrategy":"type-guard","validationCode":"fn is_plausible_millis(value: i64) -> bool {\n    // reject values that cannot scale into i64 nanoseconds: |value| < i64::MAX / 1_000_000\n    value >= 0 && value <= i64::MAX / 1_000_000\n}","typeGuard":"fn is_plausible_unit_timestamp(value: i64, unit_multiplier: i64) -> bool {\n    value >= 0 && value.checked_mul(unit_multiplier).is_some()\n}","tryCatchPattern":"let ts = match parse_millis(value, field) {\n    Ok(ts) => ts,\n    Err(e) => {\n        log::error!(\"implausible {field} value {value}: {e} - probable unit mismatch or corrupt payload\");\n        ts_init // explicit fallback, never a silent clamp\n    }\n};","preventionTips":["Confirm each Binance field's unit (ms vs us) before wiring a new endpoint into strict parsers","Alert on any timestamp that fails a plausibility bound (e.g. year > 3000) rather than letting it flow","Keep proxies/gateways from rewriting numeric fields in exchange responses"],"tags":["binance","timestamps","data-parsing","overflow","unix-nanos"],"backgroundTag":"invalid-timestamp","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}