{"record":{"id":"cedb402f10b5cf02","repo":"nautechsystems/nautilus_trader","slug":"resolved-bag-spread-spread-instrument-id-is-not","errorCode":null,"errorMessage":"Resolved BAG spread {spread_instrument_id} is not cached","messagePattern":"Resolved BAG spread (.+?) is not cached","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/providers/instruments.rs","lineNumber":541,"sourceCode":"                .with_context(|| {\n                    format!(\n                        \"Cannot resolve BAG leg con_id {} to cached instrument ID\",\n                        combo_leg.contract_id\n                    )\n                })?;\n            let ratio = IbAction::from_str(combo_leg.action.as_str())\n                .context(\"Invalid BAG combo leg action\")?\n                .signed_multiplier()\n                * combo_leg.ratio;\n\n            leg_tuples.push((leg_instrument_id, ratio));\n        }\n\n        let spread_instrument_id = create_spread_instrument_id(&leg_tuples)\n            .context(\"Failed to create spread instrument ID from BAG combo legs\")?;\n\n        if self.find(&spread_instrument_id).is_none() {\n            anyhow::bail!(\"Resolved BAG spread {spread_instrument_id} is not cached\");\n        }\n\n        Ok(spread_instrument_id)\n    }\n\n    /// Check if a security type should be filtered.\n    ///\n    /// # Arguments\n    ///\n    /// * `sec_type` - The security type to check\n    ///\n    /// # Returns\n    ///\n    /// Returns `true` if the security type should be filtered.\n    #[must_use]\n    pub fn is_filtered_sec_type(&self, sec_type: &str) -> bool {\n        self.config\n            .filter_sec_types","sourceCodeStart":523,"sourceCodeEnd":559,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/providers/instruments.rs#L523-L559","documentation":"After deriving a spread instrument ID from a BAG contract's combo legs, the adapter requires that the resulting spread instrument already exist in the provider's instrument cache. If the legs resolved to a valid spread ID but no cached instrument matches it, this error prevents returning an ID for an instrument the system has no definition for.","triggerScenarios":"resolve_spread_instrument_id_for_contract computes create_spread_instrument_id from the legs, but find(&spread_instrument_id) returns None — i.e., the spread was never loaded/defined via get_instrument or load path beforehand.","commonSituations":"Requesting a spread whose leg instruments were never subscribed/loaded, legs changed so the computed ID no longer matches any cached definition, or the spread definition was created after the resolution attempt.","solutions":["Ensure the spread instrument was created/cached first — call get_instrument (or the loader) for the spread before resolving its ID.","Check that the leg instruments composing the spread are themselves loaded and unchanged (leg changes alter the computed spread ID).","Re-run instrument loading after adapter restarts so the cache is repopulated.","If the spread is new, define it explicitly so its ID matches the combination of leg IDs and ratios."],"exampleFix":"// before: resolving before the spread is defined\nlet id = provider.resolve_instrument_id_for_contract(&bag)?;\n// after: define/load the spread first, then resolve\nlet instrument = provider.get_instrument(&client, &bag)?; // caches spread definition\nlet id = instrument.id();","handlingStrategy":"validation","validationCode":"fn spread_is_cached(provider: &IbInstrumentsProvider, id: &InstrumentId) -> bool {\n    provider.find(id).is_some()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Load the spread definition via get_instrument before resolving its ID","Repopulate the instrument cache after adapter restarts","Keep leg instruments stable — changing legs changes the spread ID"],"tags":["interactive-brokers","bag-contract","spread","cache-miss"],"backgroundTag":"record-not-found","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}