{"record":{"id":"d1e50abbc89fca10","repo":"nautechsystems/nautilus_trader","slug":"invalid-candle-close-e-d1e50a","errorCode":null,"errorMessage":"invalid candle close: {e}","messagePattern":"invalid candle close: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/websocket/parse.rs","lineNumber":406,"sourceCode":"/// 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    );\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(","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/websocket/parse.rs#L388-L424","documentation":"parse_ws_bar converts the candle's close decimal into a Price at the instrument's price_precision via Price::from_decimal_dp. Failure is wrapped as 'invalid candle close', indicating the close value cannot be represented at the configured precision.","triggerScenarios":"Candle close decimal with more fractional digits than price_precision or otherwise failing Price::from_decimal_dp in the WebSocket candle message.","commonSituations":"Instrument price_precision misconfigured; venue emitting extra decimals; wrong instrument for the candle subscription.","solutions":["Set price_precision to match the venue's actual precision","Quantize candle.c to price_precision before conversion","Log candle.c with the underlying error to diagnose","Confirm correct instrument/market mapping"],"exampleFix":"// before\nlet close = Price::from_decimal_dp(candle.c, price_precision)?;\n// after\nlet close = Price::from_decimal_dp(candle.c.round_dp(price_precision as u32), price_precision)?;","handlingStrategy":"validation","validationCode":"let close = candle.c.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 close\") => {\n        log::warn!(\"bad candle close {}, skipping bar: {e}\", candle.c);\n    }\n    other => other?,\n}","preventionTips":["Align price_precision with venue metadata","Pre-quantize candle.c before Price construction","Alert on precision mismatch clusters from the venue"],"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-14T05:17:10.506Z"}