{"record":{"id":"8c7c78368fbb0b73","repo":"nautechsystems/nautilus_trader","slug":"historical-binancebar-requests-require-last-price-8c7c78","errorCode":null,"errorMessage":"historical BinanceBar requests require LAST price type","messagePattern":"historical BinanceBar requests require LAST price type","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/data.rs","lineNumber":2246,"sourceCode":"        });\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;\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();","sourceCodeStart":2228,"sourceCodeEnd":2264,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/spot/data.rs#L2228-L2264","documentation":"Binance klines are aggregated from last-trade prices only, so historical BinanceBar requests only support PriceType::Last. A requested BarType whose price type is Bid, Mid, or Mark is rejected because the venue cannot serve that aggregation.","triggerScenarios":"request_data for BinanceBar with bar_type.spec().price_type != Last, e.g. 'BTCUSDT.BINANCE-1-MINUTE-BID-EXTERNAL' or a MID/Mark variant.","commonSituations":"Porting bar configurations from venues that offer bid/mid candles; reusing a strategy's signal BarType (often MID for FX habits) directly for crypto backfills.","solutions":["Use a LAST price type for BinanceBar requests, e.g. 'BTCUSDT.BINANCE-1-MINUTE-LAST-EXTERNAL'","If you need BID/MID history, subscribe to book data and aggregate those bars yourself instead of requesting venue klines"],"exampleFix":"# before\nbar_type = BarType.from_str(\"BTCUSDT.BINANCE-1-MINUTE-BID-EXTERNAL\")\n\n# after\nbar_type = BarType.from_str(\"BTCUSDT.BINANCE-1-MINUTE-LAST-EXTERNAL\")","handlingStrategy":"validation","validationCode":"from nautilus_trader.model.data import BarType, PriceType\n\ndef is_last_price_bar(bar_type: BarType) -> bool:\n    return bar_type.spec.price_type == PriceType.LAST\n\nassert is_last_price_bar(bar_type), \"BinanceBar history requires LAST price type\"","typeGuard":"def is_last_price_bar(bar_type) -> bool:\n    return bar_type.spec.price_type == PriceType.LAST","tryCatchPattern":null,"preventionTips":["Default Binance history requests to LAST price bars","Do not reuse MID/BID signal bar types for venue backfills","If BID/MID history is required, plan to aggregate it from book data yourself"],"tags":["binance","spot","bars","price-type","historical-data","validation"],"backgroundTag":"invalid-bar-type","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}