nautechsystems/nautilus_trader · error

cannot subscribe L1_MBP and L2_MBP for the same Binance…

Error message

cannot subscribe L1_MBP and L2_MBP for the same Binance Spot instrument

What it means

Binance Spot cannot serve L1 (top-of-book) and L2 (depth) book subscriptions simultaneously for the same instrument, and this instrument already has an active L2_MBP book subscription. The client rejects the new L1_MBP subscription to keep a single book stream per instrument.

Solutions

  1. Unsubscribe the existing L2_MBP book subscription for that instrument before subscribing L1_MBP.
  2. Use a single consistent book_type per instrument across all strategies.
  3. Check book_subscriptions/l1 state or client logs to find the conflicting subscription.

Example fix

// before
client.subscribe_book_deltas(l1_sub(btcusdt))?; // L2 already active
// after
client.unsubscribe_book_deltas(l2_sub(btcusdt))?;
client.subscribe_book_deltas(l1_sub(btcusdt))?;
Defensive patterns

Strategy: validation

Validate before calling

fn ensure_no_conflicting_book_sub(active: Option<&BookType>, requested: BookType) -> Result<(), String> {
    match (active, requested) {
        (Some(BookType::L2_MBP), BookType::L1_MBP) | (Some(BookType::L1_MBP), BookType::L2_MBP) =>
            Err("cannot mix L1 and L2 book subscriptions for one instrument".into()),
        _ => Ok(()),
    }
}

Try / catch

match client.subscribe_book_deltas(cmd) {
    Err(e) if e.to_string().contains("cannot subscribe L1_MBP and L2_MBP") => {
        log::warn!("unsubscribing existing book first");
        client.unsubscribe_book_deltas(existing_cmd)?;
        client.subscribe_book_deltas(cmd)?;
    }
    r => r?,
}

Prevention

When it happens

Trigger: Calling subscribe_book_deltas with BookType::L1_MBP for an instrument_id already present in book_subscriptions (i.e. an active L2_MBP subscription).

Common situations: Two strategies subscribing to the same instrument with different book types; re-subscribing with a changed book_type without unsubscribing first; hot-reload of config that switches L2->L1.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/93635d61befbbc42. Report an issue: GitHub.

Appendix: source

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

    }

    fn subscribe_instruments(&mut self, _cmd: SubscribeInstruments) -> anyhow::Result<()> {
        log::debug!("subscribe_instruments: Binance instruments are fetched via HTTP on connect");
        Ok(())
    }

    fn subscribe_instrument(&mut self, _cmd: SubscribeInstrument) -> anyhow::Result<()> {
        log::debug!("subscribe_instrument: Binance instruments are fetched via HTTP on connect");
        Ok(())
    }

    fn subscribe_book_deltas(&mut self, cmd: SubscribeBookDeltas) -> anyhow::Result<()> {
        if cmd.book_type == BookType::L1_MBP {
            anyhow::ensure!(
                cmd.depth.is_none_or(|depth| depth.get() == 1),
                "Binance Spot L1_MBP supports depth 1 only"
            );
            anyhow::ensure!(
                !self.book_subscriptions.contains_key(&cmd.instrument_id),
                "cannot subscribe L1_MBP and L2_MBP for the same Binance Spot instrument"
            );
            self.l1_book_subscriptions.rcu(|subscriptions| {
                *subscriptions.entry(cmd.instrument_id).or_insert(0) += 1;
            });
            self.subscribe_top_of_book(cmd.instrument_id);
            return Ok(());
        }

        if cmd.book_type != BookType::L2_MBP {
            anyhow::bail!("Binance Spot supports L1_MBP and L2_MBP order book subscriptions");
        }
        anyhow::ensure!(
            !self.l1_book_subscriptions.contains_key(&cmd.instrument_id),
            "cannot subscribe L1_MBP and L2_MBP for the same Binance Spot instrument"
        );

View on GitHub (pinned to 18893faf8b)