{"record":{"id":"1735eeaa3a865c21","repo":"nautechsystems/nautilus_trader","slug":"invalid-candle-open-e-1735ee","errorCode":null,"errorMessage":"invalid candle open: {e}","messagePattern":"invalid candle open: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/websocket/parse.rs","lineNumber":400,"sourceCode":"}\n\n/// Parses a Lighter WebSocket candle into a Nautilus [`Bar`] with `ts_event` set to the bar open.\n///\n/// # Errors\n///\n/// Returns an error if the OHLCV decimals overflow the instrument's precision, or if the\n/// timestamp cannot be converted.\npub fn parse_ws_bar(\n    instrument: &InstrumentAny,\n    candle: &LighterWsCandle,\n    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    );","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/websocket/parse.rs#L382-L418","documentation":"parse_ws_bar converts the candle's open decimal into a Price quantized to the instrument's price_precision via Price::from_decimal_dp. If the decimal is invalid for that precision (e.g. more fractional digits than precision allows, or conversion failure), the error is wrapped as 'invalid candle open'.","triggerScenarios":"A candle open value from the WebSocket that cannot be represented at the instrument's price_precision — extra decimal digits beyond precision, or a malformed/negative value.","commonSituations":"Instrument precision misconfigured lower than venue's actual precision; venue formatting change sending more decimals; wrong instrument registered for the candle subscription.","solutions":["Set the instrument's price_precision to match the venue's actual price precision for the market","Round/quantize the candle open to price_precision before constructing the Bar","Log candle.o and the underlying conversion error to identify the offending value","Confirm the correct instrument/subscription mapping"],"exampleFix":"// before\nlet open = Price::from_decimal_dp(candle.o, price_precision)?;\n// after\nlet open = Price::from_decimal_dp(candle.o.round_dp(price_precision as u32), price_precision)?;","handlingStrategy":"validation","validationCode":"let open = candle.o.round_dp(instrument.price_precision() as u32);","typeGuard":null,"tryCatchPattern":"match parse_ws_bar(candle, instrument, ...) {\n    Err(e) if e.to_string().contains(\"invalid candle open\") => {\n        log::warn!(\"bad candle open {}, skipping bar: {e}\", candle.o);\n    }\n    other => other?,\n}","preventionTips":["Keep instrument price_precision in sync with venue tick size","Round venue decimals to precision before Price construction","Log raw payloads for precision mismatches"],"tags":["rust","websocket","candles","precision"],"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-14T00:17:10.932Z"}