nautechsystems/nautilus_trader · error
Inconsistent array lengths in chart data
Error message
Inconsistent array lengths in chart data
What it means
Deribit's public/get_chart_trades (chart data) response returns parallel arrays: ticks, open, high, low, close, volume, cost. parse_bars validates that all arrays have the same length (num_bars = ticks.len()) via anyhow::ensure!; if any array is shorter/longer the OHLCV bars cannot be assembled reliably and this error is raised.
Source
Thrown at crates/adapters/deribit/src/common/parse.rs:877
chart_data: &DeribitTradingViewChartData,
bar_type: BarType,
price_precision: u8,
size_precision: u8,
use_cost_for_volume: bool,
ts_init: UnixNanos,
) -> anyhow::Result<Vec<Bar>> {
// Check status
if chart_data.status != "ok" {
anyhow::bail!(
"Chart data status is '{}', expected 'ok'",
chart_data.status
);
}
let num_bars = chart_data.ticks.len();
// Verify array lengths match
anyhow::ensure!(
chart_data.open.len() == num_bars
&& chart_data.high.len() == num_bars
&& chart_data.low.len() == num_bars
&& chart_data.close.len() == num_bars
&& chart_data.volume.len() == num_bars
&& chart_data.cost.len() == num_bars,
"Inconsistent array lengths in chart data"
);
if num_bars == 0 {
return Ok(Vec::new());
}
let mut bars = Vec::with_capacity(num_bars);
for i in 0..num_bars {
let open = Price::new_checked(chart_data.open[i], price_precision)
.with_context(|| format!("Invalid open price at index {i}"))?;View on GitHub (pinned to 18893faf8b)
Solutions
- Upgrade the nautilus deribit adapter / check Deribit API changelog for chart data response format changes.
- Retry the request — a truncated WebSocket/HTTP payload can yield short arrays.
- Reduce the requested time range or use a coarser resolution so responses are smaller and complete.
- Validate the fixture: if this happens only in tests, make mock chart data use equal-length arrays.
Example fix
// before (fixture)
let chart = ChartData { ticks: vec![t1, t2], open: vec![o1], .. };
// after
let chart = ChartData { ticks: vec![t1, t2], open: vec![o1, o2], high: vec![h1, h2], low: vec![l1, l2], close: vec![c1, c2], volume: vec![v1, v2], cost: vec![k1, k2] }; Defensive patterns
Strategy: validation
Validate before calling
// Rust let lens = [chart.open.len(), chart.high.len(), chart.low.len(), chart.close.len(), chart.volume.len(), chart.cost.len()]; anyhow::ensure!(lens.iter().all(|&l| l == chart.ticks.len()), "chart arrays misaligned");
Try / catch
match parse_bars(chart_data, bar_type) {
Ok(bars) => bars,
Err(e) if e.to_string().contains("Inconsistent array lengths") => {
log::warn!("retrying bar fetch after malformed chart response");
request_bars(...).await // retry once
}
Err(e) => return Err(e),
} Prevention
- Retry transient/truncated responses before treating them as fatal
- Keep responses small (shorter ranges, coarser resolution)
- Update fixtures and adapter together when the Deribit chart API changes
When it happens
Trigger: Calling request_bars where the Deribit chart-data response contains arrays of differing lengths — most often when the API chose the 'cost' vs 'volume' path inconsistently, a partial/truncated response, or an API schema change adds/removes an element from one series.
Common situations: Deribit API version drift changing array contents; network truncation of large chart responses; requesting a bar resolution/interval combination the endpoint returns partially for; fixtures that stub only some arrays.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Unsupported bar specification for AX: {step}-{:?}
- invalid depth {depth}; supported depths: {DERIBIT_BOOK_VALID
- Deribit does not support resolution '{resolution}'. Supporte
- Unsupported Deribit resolution: {resolution}
- Derive only supports minute intervals 1, 5, 15, 30 (use HOUR
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/75cc34ebcacffab8.
Report an issue: GitHub.