{"record":{"id":"03ae297d436e3f46","repo":"nautechsystems/nautilus_trader","slug":"cannot-start-bar-aggregation-no-instrument-found","errorCode":null,"errorMessage":"Cannot start bar aggregation: no instrument found for {}","messagePattern":"Cannot start bar aggregation: no instrument found for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/data/src/engine/mod.rs","lineNumber":4845,"sourceCode":"    }\n\n    fn create_bar_aggregator_for_key(\n        &mut self,\n        bar_type: BarType,\n        request_id: Option<UUID4>,\n        skip_first_non_full_bar: Option<bool>,\n    ) -> anyhow::Result<()> {\n        let key = bar_aggregator_key(bar_type, request_id);\n        if self.bar_aggregators.contains_key(&key) {\n            return Ok(());\n        }\n\n        let instrument = {\n            let cache = self.cache.borrow();\n            cache\n                .instrument(&bar_type.instrument_id())\n                .ok_or_else(|| {\n                    anyhow::anyhow!(\n                        \"Cannot start bar aggregation: no instrument found for {}\",\n                        bar_type.instrument_id(),\n                    )\n                })?\n                .clone()\n        };\n        let aggregator = self.create_bar_aggregator(&instrument, bar_type, skip_first_non_full_bar);\n        debug_assert_eq!(\n            aggregator.bar_type(),\n            key.0,\n            \"aggregator bar type must match its standardized key\"\n        );\n        self.bar_aggregators\n            .insert(key, Rc::new(RefCell::new(aggregator)));\n\n        Ok(())\n    }\n","sourceCodeStart":4827,"sourceCodeEnd":4863,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/data/src/engine/mod.rs#L4827-L4863","documentation":"The DataEngine refuses to start bar aggregation when the instrument for the bar's instrument ID is not present in the cache. Bar aggregation needs the instrument to determine price/size precision, tick size, and bar specification building. The engine treats a missing instrument as a hard precondition, returning anyhow::Error.","triggerScenarios":"Calling subscribe_bars (or start_bar_aggregation) with a BarType whose instrument_id was never added to the cache via cache.add_instrument, or subscribing before instrument loading completes.","commonSituations":"Backtests where instruments were never loaded into the cache; live nodes subscribing to bars for symbols not requested via instrument provider; typos or venue-format mismatches in the instrument ID; subscription racing async instrument load.","solutions":["Add the instrument to the cache before subscribing: cache.add_instrument(instrument) or request it via the instrument provider (request_instrument with the matching InstrumentId).","Verify the bar_type.instrument_id() symbol/venue matches exactly how the instrument was registered (e.g. BTCUSDT.BINANCE vs BTC-USDT.BINANCE).","Reorder startup so instrument loading/subscription completes before bar subscription.","Log and inspect cache.instrument(&bar_type.instrument_id()) at the failing point to confirm what is in the cache."],"exampleFix":"// before\nengine.subscribe_bars(&bar_type);\n// after\nif engine.cache().instrument(&bar_type.instrument_id()).is_none() {\n    engine.request_instrument(bar_type.instrument_id(), None);\n}\nengine.subscribe_bars(&bar_type);","handlingStrategy":"validation","validationCode":"if let Some(instrument) = engine.cache().instrument(&bar_type.instrument_id()) {\n    // safe to subscribe\n} else {\n    engine.request_instrument(bar_type.instrument_id(), None);\n}","typeGuard":"fn has_instrument(cache: &Cache, id: &InstrumentId) -> bool {\n    cache.instrument(id).is_some()\n}","tryCatchPattern":null,"preventionTips":["Always load instruments into the cache before any bar subscriptions.","Centralize subscription setup in one startup routine ordered after instrument loading.","Use the instrument provider to request missing instruments on demand.","Match instrument ID formatting exactly (symbol suffixes, venue codes)."],"tags":["rust","data-engine","bar-aggregation","cache-miss"],"backgroundTag":"resource-not-found","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}