{"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":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/data.rs","lineNumber":1820,"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":1802,"sourceCodeEnd":1838,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/spot/data.rs#L1802-L1838","documentation":"The Spot adapter keeps L1 (bookTicker) and L2 (depth stream) book subscriptions in separate maps per instrument; subscribing top-of-book while an L2 book subscription already exists for the same instrument would produce conflicting/mixed book semantics, so the L1 request is rejected.","triggerScenarios":"subscribe_book_deltas with L1_MBP for an instrument already present in book_subscriptions (an active L2 book subscription).","commonSituations":"One component of a stack subscribes L2 depth while another (e.g. a quoting or spread module) subscribes L1 for the same symbol; dynamic reconfiguration at runtime without unsubscribing first.","solutions":["Unsubscribe the existing L2 book-deltas subscription for that instrument before adding the L1 subscription","Standardize on one book type per instrument across all strategies; if both views are needed, derive the top of book from the L2 book instead of subscribing L1"],"exampleFix":"# before\nclient.subscribe_book_deltas(instrument_id, BookType.L2_MBP, depth=None)\nclient.subscribe_book_deltas(instrument_id, BookType.L1_MBP)  # errors: conflict\n\n# after\nclient.unsubscribe_book_deltas(instrument_id)  # drop L2 first\nclient.subscribe_book_deltas(instrument_id, BookType.L1_MBP)","handlingStrategy":"validation","validationCode":"# Track which book type is subscribed per instrument before issuing requests\nactive: dict[InstrumentId, BookType] = {}\n\ndef can_subscribe_l1(instrument_id) -> bool:\n    return active.get(instrument_id) is not BookType.L2_MBP\n\nassert can_subscribe_l1(instrument_id), \"L2 already subscribed for this instrument\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Maintain one book type per instrument across all modules","Derive the top of book from the L2 book instead of dual-subscribing","Unsubscribe before switching book types at runtime"],"tags":["binance","spot","order-book","subscription-conflict","l1-mbp","l2-mbp"],"backgroundTag":"conflicting-subscriptions","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}