{"record":{"id":"75cc34ebcacffab8","repo":"nautechsystems/nautilus_trader","slug":"inconsistent-array-lengths-in-chart-data","errorCode":null,"errorMessage":"Inconsistent array lengths in chart data","messagePattern":"Inconsistent array lengths in chart data","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/deribit/src/common/parse.rs","lineNumber":877,"sourceCode":"    chart_data: &DeribitTradingViewChartData,\n    bar_type: BarType,\n    price_precision: u8,\n    size_precision: u8,\n    use_cost_for_volume: bool,\n    ts_init: UnixNanos,\n) -> anyhow::Result<Vec<Bar>> {\n    // Check status\n    if chart_data.status != \"ok\" {\n        anyhow::bail!(\n            \"Chart data status is '{}', expected 'ok'\",\n            chart_data.status\n        );\n    }\n\n    let num_bars = chart_data.ticks.len();\n\n    // Verify array lengths match\n    anyhow::ensure!(\n        chart_data.open.len() == num_bars\n            && chart_data.high.len() == num_bars\n            && chart_data.low.len() == num_bars\n            && chart_data.close.len() == num_bars\n            && chart_data.volume.len() == num_bars\n            && chart_data.cost.len() == num_bars,\n        \"Inconsistent array lengths in chart data\"\n    );\n\n    if num_bars == 0 {\n        return Ok(Vec::new());\n    }\n\n    let mut bars = Vec::with_capacity(num_bars);\n\n    for i in 0..num_bars {\n        let open = Price::new_checked(chart_data.open[i], price_precision)\n            .with_context(|| format!(\"Invalid open price at index {i}\"))?;","sourceCodeStart":859,"sourceCodeEnd":895,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/deribit/src/common/parse.rs#L859-L895","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (fixture)\nlet chart = ChartData { ticks: vec![t1, t2], open: vec![o1], .. };\n\n// after\nlet 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] };","handlingStrategy":"validation","validationCode":"// Rust\nlet lens = [chart.open.len(), chart.high.len(), chart.low.len(), chart.close.len(), chart.volume.len(), chart.cost.len()];\nanyhow::ensure!(lens.iter().all(|&l| l == chart.ticks.len()), \"chart arrays misaligned\");","typeGuard":null,"tryCatchPattern":"match parse_bars(chart_data, bar_type) {\n    Ok(bars) => bars,\n    Err(e) if e.to_string().contains(\"Inconsistent array lengths\") => {\n        log::warn!(\"retrying bar fetch after malformed chart response\");\n        request_bars(...).await // retry once\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["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"],"tags":["deribit","rust","ohlcv","bars","validation"],"backgroundTag":"schema-validation-failed","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"}