{"record":{"id":"e1b2c83aa4339958","repo":"nautechsystems/nautilus_trader","slug":"binance-spot-kline-subscriptions-require-json-mark","errorCode":null,"errorMessage":"Binance Spot kline subscriptions require JSON market-data mode","messagePattern":"Binance Spot kline subscriptions require JSON market-data mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/data.rs","lineNumber":1974,"sourceCode":"    fn subscribe_trades(&mut self, cmd: SubscribeTrades) -> anyhow::Result<()> {\n        let instrument_id = cmd.instrument_id;\n        let ws = self.ws_client.clone();\n\n        let stream = format!(\"{}@trade\", instrument_id.symbol.as_str().to_lowercase());\n\n        self.spawn_ws(\n            async move {\n                ws.subscribe(vec![stream])\n                    .await\n                    .context(\"trades subscription\")\n            },\n            \"trade subscription\",\n        );\n        Ok(())\n    }\n\n    fn subscribe_bars(&mut self, cmd: SubscribeBars) -> anyhow::Result<()> {\n        anyhow::ensure!(\n            self.spot_market_data_mode == BinanceSpotMarketDataMode::Json,\n            \"Binance Spot kline subscriptions require JSON market-data mode\"\n        );\n        let bar_type = cmd.bar_type;\n        let ws = self.ws_client.clone();\n        let interval = bar_spec_to_binance_interval(bar_type.spec())?;\n\n        let stream = format!(\n            \"{}@kline_{}\",\n            bar_type.instrument_id().symbol.as_str().to_lowercase(),\n            interval.as_str()\n        );\n\n        self.spawn_ws(\n            async move {\n                ws.subscribe(vec![stream])\n                    .await\n                    .context(\"bars subscription\")","sourceCodeStart":1956,"sourceCodeEnd":1992,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/data.rs#L1956-L1992","documentation":"Bar (kline) subscriptions on Binance Spot are only available in JSON market-data mode, because kline streams are delivered via the public JSON WebSocket. The client rejects subscribe_bars when running in SBE mode.","triggerScenarios":"Calling subscribe_bars while spot_market_data_mode == Sbe, e.g. the adapter was configured with SBE market data and a strategy requests bar subscriptions.","commonSituations":"Running an SBE-configured data client and adding a bar-based strategy; defaults to SBE mode in config while strategy needs klines; switching data types without revisiting mode config.","solutions":["Set the Spot data client market-data mode to BinanceSpotMarketDataMode::Json in the adapter config.","Alternatively obtain bars via internal aggregation (subscribe quotes/trades and let the engine aggregate) instead of external kline streams.","Verify the mode before building strategies that need klines."],"exampleFix":"// before\nconfig.spot_market_data_mode = BinanceSpotMarketDataMode::Sbe;\n// after\nconfig.spot_market_data_mode = BinanceSpotMarketDataMode::Json; // required for kline subscriptions","handlingStrategy":"validation","validationCode":"fn bars_require_json_mode(mode: BinanceSpotMarketDataMode) -> Result<(), String> {\n    if mode == BinanceSpotMarketDataMode::Json { Ok(()) } else { Err(\"klines require JSON market-data mode\".into()) }\n}","typeGuard":null,"tryCatchPattern":"match client.subscribe_bars(cmd) {\n    Err(e) if e.to_string().contains(\"require JSON market-data mode\") => {\n        log::warn!(\"restart adapter in JSON mode or aggregate bars internally\");\n    }\n    r => r?,\n}","preventionTips":["Choose market-data mode based on all data types strategies need (bars => JSON).","Validate mode vs data requirements during node config load.","Prefer internal aggregation for bars if SBE mode is mandatory.","Document the mode/data-type matrix for the adapter."],"tags":["binance","bars","configuration","subscription"],"backgroundTag":"invalid-config-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"}