{"record":{"id":"0a72ede1341fa72b","repo":"nautechsystems/nautilus_trader","slug":"historical-binancebar-requests-require-external-ag-0a72ed","errorCode":null,"errorMessage":"historical BinanceBar requests require EXTERNAL aggregation","messagePattern":"historical BinanceBar requests require EXTERNAL aggregation","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/data.rs","lineNumber":2242,"sourceCode":"                    }\n                }\n                Err(e) => log::error!(\"Instrument request failed: {e:?}\"),\n            }\n        });\n\n        Ok(())\n    }\n\n    fn request_data(&self, request: RequestCustomData) -> anyhow::Result<()> {\n        if request.data_type.type_name() != \"BinanceBar\" {\n            log::warn!(\n                \"Unsupported custom data request: {}\",\n                request.data_type.type_name()\n            );\n            return Ok(());\n        }\n        let bar_type = parse_binance_bar_type(&request.data_type)?;\n        anyhow::ensure!(\n            bar_type.aggregation_source() == AggregationSource::External,\n            \"historical BinanceBar requests require EXTERNAL aggregation\"\n        );\n        anyhow::ensure!(\n            bar_type.spec().price_type == PriceType::Last,\n            \"historical BinanceBar requests require LAST price type\"\n        );\n        anyhow::ensure!(\n            bar_type.spec().is_time_aggregated(),\n            \"historical BinanceBar requests require time aggregation\"\n        );\n        let http = self.http_client.clone();\n        let sender = self.data_sender.clone();\n        let request_id = request.request_id;\n        let client_id = request.client_id;\n        let data_type = request.data_type;\n        let start = request.start;\n        let end = request.end;","sourceCodeStart":2224,"sourceCodeEnd":2260,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/spot/data.rs#L2224-L2260","documentation":"Historical BinanceBar (kline) requests are served by the Binance klines REST API, which only returns exchange-built candles. The requested BarType must therefore carry AggregationSource::External; a BarType with Internal aggregation (meant for client-side aggregation) is rejected by this check.","triggerScenarios":"request_data (RequestCustomData) for a DataType named 'BinanceBar' whose bar_type has aggregation_source != External, e.g. 'BTCUSDT.BINANCE-1-MINUTE-LAST-INTERNAL'.","commonSituations":"Reusing a BarType configured for internal aggregation (from a live internal aggregator) when issuing a historical backfill request; constructing bar types generically without pinning the aggregation source for history.","solutions":["Build the request BarType with AggregationSource::External, e.g. 'BTCUSDT.BINANCE-1-MINUTE-LAST-EXTERNAL'","Keep two BarTypes: External for historical/backfill requests, Internal for live client-side aggregation, and route requests accordingly"],"exampleFix":"# before\nbar_type = BarType.from_str(\"BTCUSDT.BINANCE-1-MINUTE-LAST-INTERNAL\")\n\n# after\nbar_type = BarType.from_str(\"BTCUSDT.BINANCE-1-MINUTE-LAST-EXTERNAL\")","handlingStrategy":"validation","validationCode":"from nautilus_trader.model.data import BarType, AggregationSource\n\ndef is_external_bar_type(bar_type: BarType) -> bool:\n    return bar_type.aggregation_source == AggregationSource.EXTERNAL\n\nassert is_external_bar_type(bar_type), \"BinanceBar history requires EXTERNAL aggregation\"","typeGuard":"def is_external_bar_type(bar_type) -> bool:\n    return bar_type.aggregation_source == AggregationSource.EXTERNAL","tryCatchPattern":null,"preventionTips":["Always request venue history with EXTERNAL bar types","Keep separate BarTypes for live internal aggregation vs historical backfill","Validate bar type strings end in -EXTERNAL before issuing BinanceBar requests"],"tags":["binance","spot","bars","historical-data","aggregation-source","validation"],"backgroundTag":"invalid-bar-type","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}