{"record":{"id":"f623fff7b8170706","repo":"nautechsystems/nautilus_trader","slug":"historical-binancebar-requests-require-last-price","errorCode":null,"errorMessage":"historical BinanceBar requests require LAST price type","messagePattern":"historical BinanceBar requests require LAST price type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/data.rs","lineNumber":2636,"sourceCode":"\n        Ok(())\n    }\n\n    /// 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);","sourceCodeStart":2618,"sourceCodeEnd":2654,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/futures/data.rs#L2618-L2654","documentation":"Binance klines are computed from last-trade prices only, so the custom `BinanceBar` request path enforces `PriceType::Last` on the parsed bar type. Bar types with MID, BID, or ASK price types are rejected before the HTTP fetch is spawned.","triggerScenarios":"`request_data` with data type name `BinanceBar` and a bar type like `BTCUSDT-PERP.BINANCE-1-MINUTE-MID-EXTERNAL` or `-BID-EXTERNAL` / `-ASK-EXTERNAL`.","commonSituations":"Strategies using MID bars ported from venues that serve quote-price klines; reusing a generic bar config (often MID) across venues; assuming Binance serves bid/ask candles.","solutions":["Use a LAST price type bar, e.g. `BTCUSDT-PERP.BINANCE-1-MINUTE-LAST-EXTERNAL`","If quote-price bars are required, build them locally from book/quote data (INTERNAL aggregation) rather than requesting them from Binance"],"exampleFix":"# before\nbar_type = BarType.from_str('BTCUSDT-PERP.BINANCE-1-MINUTE-MID-EXTERNAL')\n\n# after\nbar_type = BarType.from_str('BTCUSDT-PERP.BINANCE-1-MINUTE-LAST-EXTERNAL')","handlingStrategy":"validation","validationCode":"from nautilus_trader.model.enums import PriceType\n\ndef is_requestable_binance_bar(bar_type) -> bool:\n    return bar_type.spec.price_type == PriceType.LAST\n\nif not is_requestable_binance_bar(bar_type):\n    raise ValueError(f'{bar_type} uses {bar_type.spec.price_type}; Binance klines are LAST price only')","typeGuard":"def is_last_price_bar(bar_type) -> bool:\n    return bar_type.spec.price_type == PriceType.LAST","tryCatchPattern":"try:\n    actor.request_custom_data(data_type, ...)\nexcept Exception as e:\n    if 'require LAST price type' in str(e):\n        raise ValueError('Binance klines are last-trade candles; request a -LAST- bar type or aggregate quote bars locally') from e\n    raise","preventionTips":["Default all Binance bar configs to LAST price — MID/BID/ASK klines do not exist there","For quote-price candles, run a local aggregator over the book stream instead of requesting history"],"tags":["binance","futures","bars","price-type","request-validation"],"backgroundTag":"bar-price-type-not-last","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}