nautechsystems/nautilus_trader · error
invalid candle open: {e}
Error message
invalid candle open: {e} What it means
After passing the positivity checks, parse_candle_bar converts the candle's open Decimal into a Price rounded to the instrument's price precision via Price::from_decimal_dp. If that conversion fails (e.g. NaN, non-finite, or precision-related failure), the error is wrapped as 'invalid candle open'. The underlying cause from from_decimal_dp is chained in {e}.
Source
Thrown at crates/adapters/lighter/src/http/parse.rs:215
anyhow::ensure!(
candle.low > Decimal::ZERO,
"non-positive candle low `{}`",
candle.low
);
anyhow::ensure!(
candle.close > Decimal::ZERO,
"non-positive candle close `{}`",
candle.close
);
let timestamp_ms =
u64::try_from(candle.timestamp).context("negative Lighter candle timestamp")?;
let ts_event = parse_millis_to_nanos(timestamp_ms)?;
let price_precision = instrument.price_precision();
let size_precision = instrument.size_precision();
let open = Price::from_decimal_dp(candle.open, price_precision)
.map_err(|e| anyhow::anyhow!("invalid candle open: {e}"))?;
let high = Price::from_decimal_dp(candle.high, price_precision)
.map_err(|e| anyhow::anyhow!("invalid candle high: {e}"))?;
let low = Price::from_decimal_dp(candle.low, price_precision)
.map_err(|e| anyhow::anyhow!("invalid candle low: {e}"))?;
let close = Price::from_decimal_dp(candle.close, price_precision)
.map_err(|e| anyhow::anyhow!("invalid candle close: {e}"))?;
anyhow::ensure!(
candle.volume_base.is_sign_positive(),
"negative candle volume `{}`",
candle.volume_base,
);
let volume = Quantity::from_decimal_dp(candle.volume_base, size_precision)
.map_err(|e| anyhow::anyhow!("invalid candle volume: {e}"))?;
Bar::new_checked(bar_type, open, high, low, close, volume, ts_event, ts_init)
.context("failed to construct Bar from Lighter candle")
}
View on GitHub (pinned to 18893faf8b)
Solutions
- Read the chained cause {e} to see why Price::from_decimal_dp failed
- Ensure the correct instrument (matching the bar_type/instrument_id) with the right price_precision is passed in
- Sanitize/validate candle decimals (finite, within instrument price bounds) before parsing
- Check the Lighter API response for anomalous open values
Example fix
// before
let open = Price::from_decimal_dp(candle.open, price_precision)
.map_err(|e| anyhow::anyhow!("invalid candle open: {e}"))?;
// after
anyhow::ensure!(candle.open.is_finite(), "non-finite candle open");
let open = Price::from_decimal_dp(candle.open, price_precision)
.map_err(|e| anyhow::anyhow!("invalid candle open: {e}"))?; Defensive patterns
Strategy: try-catch
Validate before calling
anyhow::ensure!(candle.open.is_finite(), "non-finite candle open: {}", candle.open); Type guard
fn convertible_open(c: &LighterCandle, precision: u8) -> bool {
c.open.is_finite() && c.open > Decimal::ZERO
} Try / catch
let open = Price::from_decimal_dp(candle.open, price_precision)
.map_err(|e| anyhow::anyhow!("invalid candle open: {e}"))
.with_context(|| format!("candle for {}", instrument.id()))?; Prevention
- Ensure the instrument passed to the parser is the one matching the candle's instrument_id
- Confirm the instrument's price_precision reflects the market tick size
- Validate candle decimals are finite before conversion
- Check adapter/API version alignment when decimal scaling changes
When it happens
Trigger: A LighterCandle.open Decimal that Price::from_decimal_dp rejects for the instrument's price_precision — e.g. non-finite decimal values from upstream data, or a mismatch between the instrument definition and the candle's decimal scale.
Common situations: Upstream API emitting NaN/inf-like values; using an instrument whose price_precision doesn't accommodate the candle's decimals; parsing candles with the wrong instrument object.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- invalid candle high: {e}
- invalid candle low: {e}
- invalid candle close: {e}
- invalid candle volume: {e}
- invalid candle open: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/0cbb238f038e0a1f.
Report an issue: GitHub.