nautechsystems/nautilus_trader · error · anyhow::Error

Binance Spot kline subscriptions require JSON market-data mo

Error message

Binance Spot kline subscriptions require JSON market-data mode

What it means

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.

Source

Thrown at crates/adapters/binance/src/spot/data.rs:1958

    fn subscribe_trades(&mut self, cmd: SubscribeTrades) -> anyhow::Result<()> {
        let instrument_id = cmd.instrument_id;
        let ws = self.ws_client.clone();

        let stream = format!("{}@trade", instrument_id.symbol.as_str().to_lowercase());

        self.spawn_ws(
            async move {
                ws.subscribe(vec![stream])
                    .await
                    .context("trades subscription")
            },
            "trade subscription",
        );
        Ok(())
    }

    fn subscribe_bars(&mut self, cmd: SubscribeBars) -> anyhow::Result<()> {
        anyhow::ensure!(
            self.spot_market_data_mode == BinanceSpotMarketDataMode::Json,
            "Binance Spot kline subscriptions require JSON market-data mode"
        );
        let bar_type = cmd.bar_type;
        let ws = self.ws_client.clone();
        let interval = bar_spec_to_binance_interval(bar_type.spec())?;

        let stream = format!(
            "{}@kline_{}",
            bar_type.instrument_id().symbol.as_str().to_lowercase(),
            interval.as_str()
        );

        self.spawn_ws(
            async move {
                ws.subscribe(vec![stream])
                    .await
                    .context("bars subscription")

View on GitHub (pinned to a4b06ed870)

Solutions

  1. Set spot_market_data_mode to Json in the Binance Spot data client config when you need live venue klines
  2. Or stay in SBE and build bars yourself from trade/quote ticks instead of subscribing to venue klines
  3. Remember the same JSON-only restriction applies to BinanceSpotTicker custom data

Example fix

# before
config = BinanceSpotDataClientConfig(
    spot_market_data_mode=BinanceSpotMarketDataMode.SBE,
)
# strategy calls subscribe_bars(...) -> error

# after
config = BinanceSpotDataClientConfig(
    spot_market_data_mode=BinanceSpotMarketDataMode.JSON,
)
Defensive patterns

Strategy: validation

Validate before calling

mode = config.spot_market_data_mode
assert not (wants_live_bars and mode != BinanceSpotMarketDataMode.JSON), (
    "Live Binance Spot klines require JSON market-data mode"
)

Prevention

When it happens

Trigger: subscribe_bars (any BarType) on the Binance Spot data client while spot_market_data_mode == Sbe.

Common situations: 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.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@a4b06ed870 (2026-08-16). Data as JSON: /api/errors/e1b2c83aa4339958. Report an issue: GitHub.