{"record":{"id":"ba6786af40d1aded","repo":"nautechsystems/nautilus_trader","slug":"binance-historical-bars-require-external-aggregati","errorCode":null,"errorMessage":"Binance historical bars require EXTERNAL aggregation","messagePattern":"Binance historical bars require EXTERNAL aggregation","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/data.rs","lineNumber":3048,"sourceCode":"        });\n\n        Ok(())\n    }\n\n    fn request_bars(&self, request: RequestBars) -> anyhow::Result<()> {\n        let http = self.http_client.clone();\n        let sender = self.data_sender.clone();\n        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(","sourceCodeStart":3030,"sourceCodeEnd":3066,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/futures/data.rs#L3030-L3066","documentation":"Binance historical bar requests can only be served from Binance's REST kline API, so the bar type must use AggregationSource::External (bars aggregated by the exchange). This ensure! in request_bars rejects internally aggregated bar types, which Nautilus would otherwise have to synthesize from historical trades.","triggerScenarios":"Requesting historical bars where the BarType was built with aggregation_source Internal (e.g. created programmatically with BarType::new(..., AggregationSource::Internal), or from a spec string without -EXTERNAL suffix, which defaults to internal in some APIs).","commonSituations":"Users build bar types for live streaming with internal aggregation (common for tick bars), then reuse the same BarType for a historical request; the historical lookup path rejects it.","solutions":["Construct the BarType with AggregationSource::External for historical requests","Use a bar-type string with the -EXTERNAL suffix, e.g. 'BTCUSDT-PERP.BINANCE-1-MINUTE-LAST-EXTERNAL'","Keep separate BarTypes: internal for streaming, external for historical lookups"],"exampleFix":"// before\nlet bar_type = BarType::new(instrument_id, spec, AggregationSource::Internal);\n// after\nlet bar_type = BarType::new(instrument_id, spec, AggregationSource::External);","handlingStrategy":"validation","validationCode":"let ok = bar_type.aggregation_source() == AggregationSource::External;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use separate bar types for streaming (internal) and history (external)","Parse bar types from strings with an explicit -EXTERNAL suffix for historical requests"],"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"}