{"record":{"id":"7b3f24927b0a5392","repo":"nautechsystems/nautilus_trader","slug":"invalid-negative-binance-field-timestamp-value","errorCode":null,"errorMessage":"invalid negative Binance {field} timestamp: {value}","messagePattern":"invalid negative Binance (.+?) timestamp: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/common/parse.rs","lineNumber":90,"sourceCode":"const CONTRACT_TYPE_CURRENT_QUARTER: &str = \"CURRENT_QUARTER\";\nconst CONTRACT_TYPE_NEXT_QUARTER: &str = \"NEXT_QUARTER\";\n\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) => {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/common/parse.rs#L72-L108","documentation":"Binance timestamps are converted to UnixNanos via checked constructors; a negative i64 cannot be represented as pre-epoch nanos in this domain type and is rejected. Binance commonly uses -1 as a 'not available' sentinel, which some fields legitimately carry and this strict parse refuses.","triggerScenarios":"A REST/stream payload contains a negative value (typically -1) in a timestamp field the adapter parses strictly via parse_millis/parse_micros - e.g. an optional event time absent for a newly listed or partially populated instrument.","commonSituations":"Replaying captured data whose sentinel fields were not normalized; a Binance endpoint starting to populate an optional time with -1; upstream schema drift on specific symbols.","solutions":["Identify the offending field from the {field} placeholder, then inspect the raw Binance payload - -1 means 'absent', not a valid time","Update the adapter to a version handling the sentinel for that field, or report the field to maintainers","If replaying old captures, regenerate/normalize them so absent times are omitted rather than -1"],"exampleFix":"// before: strict parse of a sentinel-carrying field\nlet ts = parse_millis(raw_time, \"eventTime\")?;\n\n// after: treat the -1 sentinel as absent\nlet ts = if raw_time < 0 { fallback_ts } else { parse_millis(raw_time, \"eventTime\")? };","handlingStrategy":"type-guard","validationCode":"fn is_representable_timestamp(value: i64) -> bool {\n    value >= 0\n}","typeGuard":"fn is_non_negative_timestamp(value: i64) -> bool {\n    value >= 0\n}","tryCatchPattern":"let ts = parse_millis(value, field).unwrap_or_else(|e| {\n    log::warn!(\"invalid {field} timestamp {value} ({e}) - using event ts_init fallback\");\n    ts_init\n});","preventionTips":["When replaying captured Binance data, normalize -1 sentinel times to absent","Log the field name and raw value on timestamp parse failures to spot schema drift early","Validate third-party data feeds for sentinel usage before piping them into the adapter"],"tags":["binance","timestamps","data-parsing","unix-nanos"],"backgroundTag":"invalid-timestamp","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}