{"record":{"id":"0abb659b623c4a86","repo":"nautechsystems/nautilus_trader","slug":"negative-candle-timestamp","errorCode":null,"errorMessage":"negative candle timestamp: {}","messagePattern":"negative candle timestamp: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/websocket/parse.rs","lineNumber":411,"sourceCode":"    resolution: LighterCandleResolution,\n    ts_init: UnixNanos,\n) -> anyhow::Result<Bar> {\n    let price_precision = instrument.price_precision();\n    let size_precision = instrument.size_precision();\n\n    let open = Price::from_decimal_dp(candle.o, price_precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid candle open: {e}\"))?;\n    let high = Price::from_decimal_dp(candle.h, price_precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid candle high: {e}\"))?;\n    let low = Price::from_decimal_dp(candle.l, price_precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid candle low: {e}\"))?;\n    let close = Price::from_decimal_dp(candle.c, price_precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid candle close: {e}\"))?;\n    let volume = Quantity::from_decimal_dp(candle.v, size_precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid candle volume: {e}\"))?;\n\n    let t_ms = u64::try_from(candle.t)\n        .map_err(|_| anyhow::anyhow!(\"negative candle timestamp: {}\", candle.t))?;\n    let ts_event = parse_millis_to_nanos(t_ms)?;\n\n    let bar_type = BarType::new(\n        instrument.id(),\n        resolution.to_bar_spec(),\n        AggregationSource::External,\n    );\n\n    Bar::new_checked(bar_type, open, high, low, close, volume, ts_event, ts_init)\n        .map_err(|e| anyhow::anyhow!(\"invalid candle bar: {e}\"))\n}\n\nfn parse_book_level_delta(\n    level: &LighterPriceLevel,\n    instrument: &InstrumentAny,\n    side: OrderSide,\n    sequence: u64,\n    ts_event: UnixNanos,","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/websocket/parse.rs#L393-L429","documentation":"parse_ws_bar casts the candle's timestamp (milliseconds, as i64) to u64 before converting to nanoseconds. A negative timestamp cannot be cast losslessly, so the adapter raises 'negative candle timestamp' rather than producing a corrupted event time.","triggerScenarios":"A candle message with candle.t < 0 — malformed venue payload, integer underflow upstream, or a misparsed field causing the signed timestamp to go negative.","commonSituations":"Venue protocol/schema change; clock or epoch issues producing negative times; deserialization bug mapping the wrong JSON field to t.","solutions":["Log the raw candle payload and check the venue schema for the timestamp field","Reject or skip messages with negative timestamps upstream before parsing","Update the parser if the venue changed the timestamp format/epoch","Validate deserialization maps the correct JSON field to candle.t"],"exampleFix":"// before\nlet t_ms = u64::try_from(candle.t)?;\n// after\nif candle.t < 0 { log::warn!(\"skipping candle with negative timestamp {}\", candle.t); return Ok(None); }\nlet t_ms = u64::try_from(candle.t)?;","handlingStrategy":"validation","validationCode":"if candle.t < 0 {\n    log::warn!(\"negative candle timestamp {}\", candle.t);\n    return; // skip bad candle\n}","typeGuard":"fn has_valid_timestamp(candle: &WsCandle) -> bool { candle.t >= 0 }","tryCatchPattern":"match parse_ws_bar(candle, instrument, ...) {\n    Err(e) if e.to_string().contains(\"negative candle timestamp\") => {\n        log::warn!(\"skipping malformed candle: {e}\");\n    }\n    other => other?,\n}","preventionTips":["Validate timestamps on ingest before parsing","Watch for venue schema changes to the timestamp field","Skip-and-log malformed candles instead of failing the stream"],"tags":["rust","websocket","candles","timestamp"],"backgroundTag":"invalid-argument-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}