{"record":{"id":"93635d61befbbc42","repo":"nautechsystems/nautilus_trader","slug":"cannot-subscribe-l1-mbp-and-l2-mbp-for-the-same-bi-93635d","errorCode":null,"errorMessage":"cannot subscribe L1_MBP and L2_MBP for the same Binance Spot instrument","messagePattern":"cannot subscribe L1_MBP and L2_MBP for the same Binance Spot instrument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/data.rs","lineNumber":1836,"sourceCode":"    }\n\n    fn subscribe_instruments(&mut self, _cmd: SubscribeInstruments) -> anyhow::Result<()> {\n        log::debug!(\"subscribe_instruments: Binance instruments are fetched via HTTP on connect\");\n        Ok(())\n    }\n\n    fn subscribe_instrument(&mut self, _cmd: SubscribeInstrument) -> anyhow::Result<()> {\n        log::debug!(\"subscribe_instrument: Binance instruments are fetched via HTTP on connect\");\n        Ok(())\n    }\n\n    fn subscribe_book_deltas(&mut self, cmd: SubscribeBookDeltas) -> anyhow::Result<()> {\n        if cmd.book_type == BookType::L1_MBP {\n            anyhow::ensure!(\n                cmd.depth.is_none_or(|depth| depth.get() == 1),\n                \"Binance Spot L1_MBP supports depth 1 only\"\n            );\n            anyhow::ensure!(\n                !self.book_subscriptions.contains_key(&cmd.instrument_id),\n                \"cannot subscribe L1_MBP and L2_MBP for the same Binance Spot instrument\"\n            );\n            self.l1_book_subscriptions.rcu(|subscriptions| {\n                *subscriptions.entry(cmd.instrument_id).or_insert(0) += 1;\n            });\n            self.subscribe_top_of_book(cmd.instrument_id);\n            return Ok(());\n        }\n\n        if cmd.book_type != BookType::L2_MBP {\n            anyhow::bail!(\"Binance Spot supports L1_MBP and L2_MBP order book subscriptions\");\n        }\n        anyhow::ensure!(\n            !self.l1_book_subscriptions.contains_key(&cmd.instrument_id),\n            \"cannot subscribe L1_MBP and L2_MBP for the same Binance Spot instrument\"\n        );\n","sourceCodeStart":1818,"sourceCodeEnd":1854,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/data.rs#L1818-L1854","documentation":"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.","triggerScenarios":"Calling subscribe_book_deltas with BookType::L1_MBP for an instrument_id already present in book_subscriptions (i.e. an active L2_MBP subscription).","commonSituations":"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.","solutions":["Unsubscribe the existing L2_MBP book subscription for that instrument before subscribing L1_MBP.","Use a single consistent book_type per instrument across all strategies.","Check book_subscriptions/l1 state or client logs to find the conflicting subscription."],"exampleFix":"// before\nclient.subscribe_book_deltas(l1_sub(btcusdt))?; // L2 already active\n// after\nclient.unsubscribe_book_deltas(l2_sub(btcusdt))?;\nclient.subscribe_book_deltas(l1_sub(btcusdt))?;","handlingStrategy":"validation","validationCode":"fn ensure_no_conflicting_book_sub(active: Option<&BookType>, requested: BookType) -> Result<(), String> {\n    match (active, requested) {\n        (Some(BookType::L2_MBP), BookType::L1_MBP) | (Some(BookType::L1_MBP), BookType::L2_MBP) =>\n            Err(\"cannot mix L1 and L2 book subscriptions for one instrument\".into()),\n        _ => Ok(()),\n    }\n}","typeGuard":null,"tryCatchPattern":"match client.subscribe_book_deltas(cmd) {\n    Err(e) if e.to_string().contains(\"cannot subscribe L1_MBP and L2_MBP\") => {\n        log::warn!(\"unsubscribing existing book first\");\n        client.unsubscribe_book_deltas(existing_cmd)?;\n        client.subscribe_book_deltas(cmd)?;\n    }\n    r => r?,\n}","preventionTips":["Track active book subscriptions per instrument in your application.","Use one book type per instrument across all strategies.","Unsubscribe before switching book types.","Check adapter logs/state for existing subscriptions before subscribing."],"tags":["binance","orderbook","subscription","conflict"],"backgroundTag":"invalid-state-transition","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"}