{"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":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/data.rs","lineNumber":1958,"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":1940,"sourceCodeEnd":1976,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/spot/data.rs#L1940-L1976","documentation":"Binance Spot kline/candlestick subscriptions are implemented only on the JSON public stream (symbol@kline_<interval>). Any subscribe_bars call on this client fails this check while spot_market_data_mode is Sbe, regardless of the bar type, because the SBE client has no kline stream support.","triggerScenarios":"subscribe_bars (any BarType) on the Binance Spot data client while spot_market_data_mode == Sbe.","commonSituations":"Switching to SBE for lower-latency book/trade data and forgetting that live bars still need JSON mode; reusing a JSON-mode strategy config with only the mode flag flipped to SBE.","solutions":["Set spot_market_data_mode to Json in the Binance Spot data client config when you need live venue klines","Or stay in SBE and build bars yourself from trade/quote ticks instead of subscribing to venue klines","Remember the same JSON-only restriction applies to BinanceSpotTicker custom data"],"exampleFix":"# before\nconfig = BinanceSpotDataClientConfig(\n    spot_market_data_mode=BinanceSpotMarketDataMode.SBE,\n)\n# strategy calls subscribe_bars(...) -> error\n\n# after\nconfig = BinanceSpotDataClientConfig(\n    spot_market_data_mode=BinanceSpotMarketDataMode.JSON,\n)","handlingStrategy":"validation","validationCode":"mode = config.spot_market_data_mode\nassert not (wants_live_bars and mode != BinanceSpotMarketDataMode.JSON), (\n    \"Live Binance Spot klines require JSON market-data mode\"\n)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Audit bar subscriptions when switching to SBE mode","Keep a Json-mode config for strategies that need venue klines","Aggregate bars from trades client-side if SBE latency matters more than venue bars"],"tags":["binance","spot","sbe","bars","kline","configuration"],"backgroundTag":"market-data-mode-mismatch","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}