nautechsystems/nautilus_trader · error
invalid candle volume: {e}
Error message
invalid candle volume: {e} What it means
parse_ws_bar converts the candle's volume decimal into a Quantity at the instrument's size_precision via Quantity::from_decimal_dp. Failure is wrapped as 'invalid candle volume', meaning the venue's volume value cannot be represented at the configured size precision.
Source
Thrown at crates/adapters/lighter/src/websocket/parse.rs:408
pub fn parse_ws_bar(
instrument: &InstrumentAny,
candle: &LighterWsCandle,
resolution: LighterCandleResolution,
ts_init: UnixNanos,
) -> anyhow::Result<Bar> {
let price_precision = instrument.price_precision();
let size_precision = instrument.size_precision();
let open = Price::from_decimal_dp(candle.o, price_precision)
.map_err(|e| anyhow::anyhow!("invalid candle open: {e}"))?;
let high = Price::from_decimal_dp(candle.h, price_precision)
.map_err(|e| anyhow::anyhow!("invalid candle high: {e}"))?;
let low = Price::from_decimal_dp(candle.l, price_precision)
.map_err(|e| anyhow::anyhow!("invalid candle low: {e}"))?;
let close = Price::from_decimal_dp(candle.c, price_precision)
.map_err(|e| anyhow::anyhow!("invalid candle close: {e}"))?;
let volume = Quantity::from_decimal_dp(candle.v, size_precision)
.map_err(|e| anyhow::anyhow!("invalid candle volume: {e}"))?;
let t_ms = u64::try_from(candle.t)
.map_err(|_| anyhow::anyhow!("negative candle timestamp: {}", candle.t))?;
let ts_event = parse_millis_to_nanos(t_ms)?;
let bar_type = BarType::new(
instrument.id(),
resolution.to_bar_spec(),
AggregationSource::External,
);
Bar::new_checked(bar_type, open, high, low, close, volume, ts_event, ts_init)
.map_err(|e| anyhow::anyhow!("invalid candle bar: {e}"))
}
fn parse_book_level_delta(
level: &LighterPriceLevel,
instrument: &InstrumentAny,View on GitHub (pinned to 18893faf8b)
Solutions
- Correct the instrument's size_precision to match venue volume precision
- Round candle.v to size_precision before constructing the Quantity
- Log the offending volume value and root error
- Verify the instrument definition's size precision against venue metadata
Example fix
// before let volume = Quantity::from_decimal_dp(candle.v, size_precision)?; // after let volume = Quantity::from_decimal_dp(candle.v.round_dp(size_precision as u32), size_precision)?;
Defensive patterns
Strategy: validation
Validate before calling
let volume = candle.v.round_dp(instrument.size_precision() as u32);
Try / catch
match parse_ws_bar(candle, instrument, ...) {
Err(e) if e.to_string().contains("invalid candle volume") => {
log::warn!("bad candle volume {}, skipping bar: {e}", candle.v);
}
other => other?,
} Prevention
- Set size_precision from venue instrument metadata
- Pre-quantize candle.v before Quantity construction
- Verify base/quote volume units on the instrument definition
When it happens
Trigger: Candle volume decimal with more fractional digits than size_precision or otherwise failing Quantity construction from the WebSocket candle payload.
Common situations: Instrument size_precision misconfigured (too few decimals); venue emitting higher-precision volumes; base/quote sizing mix-up on the instrument definition.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- invalid candle open: {e}
- invalid candle high: {e}
- invalid candle low: {e}
- invalid candle close: {e}
- invalid candle open: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/44631fc54ea4b908.
Report an issue: GitHub.