{"record":{"id":"255c2faae3518dea","repo":"nautechsystems/nautilus_trader","slug":"historical-binancebar-requests-require-time-aggreg","errorCode":null,"errorMessage":"historical BinanceBar requests require time aggregation","messagePattern":"historical BinanceBar requests require time aggregation","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/data.rs","lineNumber":2686,"sourceCode":"    /// Requests Binance futures custom data.\n    ///\n    /// Spawned fetch failures are logged and no response is emitted, matching\n    /// the existing request-path behavior for other Binance adapter requests.\n    fn request_data(&self, request: RequestCustomData) -> anyhow::Result<()> {\n        let data_type = request.data_type.clone();\n        let data_type_name = data_type.type_name().to_string();\n\n        if data_type_name == \"BinanceBar\" {\n            let bar_type = parse_binance_bar_type(&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 start = request.start;\n            let end = request.end;\n            let limit = request.limit.map(|value| value.get() as u32);\n            let params = request.params;\n            let clock = self.clock;\n            let venue = self.venue();\n            let start_nanos = datetime_to_unix_nanos(start);\n            let end_nanos = datetime_to_unix_nanos(end);\n            self.spawn_command(async move {\n                match http.request_binance_bars(bar_type, start, end, limit).await {\n                    Ok(bars) => {","sourceCodeStart":2668,"sourceCodeEnd":2704,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/futures/data.rs#L2668-L2704","documentation":"NautilusTrader's Binance Futures data client refuses historical bar requests unless the bar type uses externally aggregated, time-based bars of LAST price type, because Binance's REST kline endpoint is the only supported source and it returns time-binned trades. This ensure! guards request_data so unsupported bar specs fail fast with a clear message instead of producing wrong or empty data.","triggerScenarios":"Calling DataEngine.request(BarsRequest) (or a historical request via the Binance Futures data client) with a BarType whose aggregation_source is Internal (Nautilus aggregating from trades/ticks), whose price_type is not Last (e.g. Bid/Ask/Mid), or whose aggregation is tick/volume/dollar-based rather than time-based (e.g. 100-tick bars).","commonSituations":"Users configure bar types like 'BTCUSDT-PERP.BINANCE-100-TICK-LAST-INTERNAL' or bid/ask bars, then request historical data. Works in live streaming (internal aggregation) but fails on historical lookup because Binance cannot serve it.","solutions":["Change the BarType to EXTERNAL aggregation, e.g. BarType.from_str('BTCUSDT-PERP.BINANCE-1-MINUTE-LAST-EXTERNAL')","Ensure price_type is PriceType.LAST in the bar spec","Use a time-based aggregation (SECOND/MINUTE/HOUR/DAY spec) instead of tick/volume/dollar aggregation","If you need internal aggregation, generate bars from streamed trades/ticks instead of requesting historical bars"],"exampleFix":"// before\nlet bar_type = BarType::from_str(\"BTCUSDT-PERP.BINANCE-100-TICK-LAST-INTERNAL\")?;\n// after\nlet bar_type = BarType::from_str(\"BTCUSDT-PERP.BINANCE-1-MINUTE-LAST-EXTERNAL\")?;","handlingStrategy":"validation","validationCode":"fn valid_historical_bar_type(bar_type: &BarType) -> bool {\n    bar_type.aggregation_source() == AggregationSource::External\n        && bar_type.spec().price_type == PriceType::Last\n        && bar_type.spec().is_time_aggregated()\n}","typeGuard":null,"tryCatchPattern":"match client.request_data(request) {\n    Err(e) if e.to_string().contains(\"require\") => eprintln!(\"unsupported bar type: {e}\"),\n    Err(e) => return Err(e),\n    Ok(_) => {},\n}","preventionTips":["Define historical-request bar types with explicit -EXTERNAL suffix strings","Only use LAST price type with Binance","Restrict Binance history to time-based bar specs"],"tags":["binance","validation","bar-type","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"}