{"record":{"id":"d74381e78a52d642","repo":"nautechsystems/nautilus_trader","slug":"binance-historical-bars-require-time-aggregation","errorCode":null,"errorMessage":"Binance historical bars require time aggregation","messagePattern":"Binance historical bars require time aggregation","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/data.rs","lineNumber":3056,"sourceCode":"        let bar_type = request.bar_type;\n        let start = request.start;\n        let end = request.end;\n        let limit = request.limit.map(|n| n.get() as u32);\n        let request_id = request.request_id;\n        let client_id = request.client_id.unwrap_or(self.client_id);\n        let params = request.params;\n        let clock = self.clock;\n        let start_nanos = datetime_to_unix_nanos(start);\n        let end_nanos = datetime_to_unix_nanos(end);\n        anyhow::ensure!(\n            bar_type.aggregation_source() == AggregationSource::External,\n            \"Binance historical bars require EXTERNAL aggregation\"\n        );\n        anyhow::ensure!(\n            bar_type.spec().price_type == PriceType::Last,\n            \"Binance historical bars require LAST price type\"\n        );\n        anyhow::ensure!(\n            bar_type.spec().is_time_aggregated(),\n            \"Binance historical bars require time aggregation\"\n        );\n\n        self.spawn_command(async move {\n            let result = http.request_bars(bar_type, start, end, limit).await;\n\n            match result.context(\"failed to request bars from Binance Futures\") {\n                Ok(bars) => {\n                    let response = DataResponse::Bars(BarsResponse::new(\n                        request_id,\n                        client_id,\n                        bar_type,\n                        bars,\n                        start_nanos,\n                        end_nanos,\n                        clock.get_time_ns(),\n                        params,","sourceCodeStart":3038,"sourceCodeEnd":3074,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/futures/data.rs#L3038-L3074","documentation":"Binance klines are time-interval candles (1m, 5m, 1h, ...), so the Binance Futures data client requires the bar spec to be time-aggregated for historical requests. Tick-, volume-, and dollar-based aggregations are rejected in request_bars because the exchange cannot serve them.","triggerScenarios":"Requesting historical bars with a non-time aggregation in the spec, e.g. 'BTCUSDT-PERP.BINANCE-100-TICK-LAST-EXTERNAL' or '-1000-VOLUME-LAST-EXTERNAL'.","commonSituations":"Backtests requesting volume bars historically from Binance; volume/tick bars must instead be aggregated by Nautilus from downloaded trades/ticks.","solutions":["Use a time-based step (SECOND, MINUTE, HOUR, DAY) in the bar spec, e.g. 'BTCUSDT-PERP.BINANCE-5-MINUTE-LAST-EXTERNAL'","Download historical trades/ticks and aggregate into tick/volume bars internally in NautilusTrader","Pre-compute custom bars offline and load them from a catalog instead of requesting from the adapter"],"exampleFix":"// before\nlet bar_type = BarType::from_str(\"BTCUSDT-PERP.BINANCE-1000-VOLUME-LAST-EXTERNAL\")?;\n// after\nlet bar_type = BarType::from_str(\"BTCUSDT-PERP.BINANCE-1-HOUR-LAST-EXTERNAL\")?;","handlingStrategy":"validation","validationCode":"let ok = bar_type.spec().is_time_aggregated();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use SECOND/MINUTE/HOUR/DAY specs for Binance historical bars","Build tick/volume bars from trades via internal aggregation in a backtest engine or from catalog data"],"tags":["binance","bar-type","aggregation","historical-data"],"backgroundTag":"invalid-argument-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}