{"record":{"id":"93d5c62b9c2e9c4b","repo":"nautechsystems/nautilus_trader","slug":"invalid-candle-close-e","errorCode":null,"errorMessage":"invalid candle close: {e}","messagePattern":"invalid candle close: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/http/parse.rs","lineNumber":221,"sourceCode":"        candle.close > Decimal::ZERO,\n        \"non-positive candle close `{}`\",\n        candle.close\n    );\n\n    let timestamp_ms =\n        u64::try_from(candle.timestamp).context(\"negative Lighter candle timestamp\")?;\n    let ts_event = parse_millis_to_nanos(timestamp_ms)?;\n    let price_precision = instrument.price_precision();\n    let size_precision = instrument.size_precision();\n\n    let open = Price::from_decimal_dp(candle.open, price_precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid candle open: {e}\"))?;\n    let high = Price::from_decimal_dp(candle.high, price_precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid candle high: {e}\"))?;\n    let low = Price::from_decimal_dp(candle.low, price_precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid candle low: {e}\"))?;\n    let close = Price::from_decimal_dp(candle.close, price_precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid candle close: {e}\"))?;\n    anyhow::ensure!(\n        candle.volume_base.is_sign_positive(),\n        \"negative candle volume `{}`\",\n        candle.volume_base,\n    );\n    let volume = Quantity::from_decimal_dp(candle.volume_base, size_precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid candle volume: {e}\"))?;\n\n    Bar::new_checked(bar_type, open, high, low, close, volume, ts_event, ts_init)\n        .context(\"failed to construct Bar from Lighter candle\")\n}\n\n/// Parses a Lighter historical funding row into a Nautilus [`FundingRateUpdate`].\n///\n/// Lighter returns `rate` as a magnitude and `direction` as the side paying\n/// the funding. Nautilus uses the conventional signed rate: positive when\n/// longs pay shorts and negative when shorts pay longs.\n///","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/http/parse.rs#L203-L239","documentation":"This wraps a failure converting the candle's close Decimal to a Price at the instrument's price_precision in parse_candle_bar. Price::from_decimal_dp refused the value, so the Bar cannot be built; the underlying reason is attached as the error cause.","triggerScenarios":"LighterCandle.close failing Price::from_decimal_dp(close, price_precision) while parsing candles through parse_bars — non-finite values, or decimals incompatible with the instrument's precision.","commonSituations":"Malformed upstream closes (NaN/inf); mismatched instrument precision; adapter/version drift where the API returns differently scaled decimals.","solutions":["Read the chained cause to identify why from_decimal_dp rejected the close","Verify the instrument's price_precision matches the market's actual tick size","Sanitize finite-ness and scale of candle decimals before parsing","Check the raw Lighter candles payload for bad close values"],"exampleFix":"// before\nlet close = Price::from_decimal_dp(candle.close, price_precision)?;\n// after\nlet close = Price::from_decimal_dp(candle.close.round_dp(price_precision as u32), price_precision)?;","handlingStrategy":"try-catch","validationCode":"anyhow::ensure!(candle.close.is_finite(), \"non-finite candle close: {}\", candle.close);","typeGuard":"fn convertible_close(c: &LighterCandle, precision: u8) -> bool {\n    c.close.is_finite() && c.close > Decimal::ZERO\n}","tryCatchPattern":"let close = Price::from_decimal_dp(candle.close, price_precision)\n    .map_err(|e| anyhow::anyhow!(\"invalid candle close: {e}\"))\n    .with_context(|| format!(\"candle for {}\", instrument.id()))?;","preventionTips":["Ensure instrument price_precision accommodates the API's decimal scale","Sanitize closes (finite, positive) before conversion","Pin adapter expectations to the current Lighter candles schema","Fail with context including instrument id to speed diagnosis"],"tags":["rust","price-conversion","candles","precision"],"backgroundTag":"invalid-argument-format","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"}