{"record":{"id":"33d4e92dbeb43074","repo":"nautechsystems/nautilus_trader","slug":"invalid-config-type-for-interactivebrokersexecutio","errorCode":null,"errorMessage":"Invalid config type for InteractiveBrokersExecutionClientFactory. Expected InteractiveBrokersExecutionClientConfig, was {config:?}","messagePattern":"Invalid config type for InteractiveBrokersExecutionClientFactory\\. Expected InteractiveBrokersExecutionClientConfig, was (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/factories.rs","lineNumber":159,"sourceCode":"    #[must_use]\n    pub const fn new() -> Self {\n        Self\n    }\n}\n\nimpl ExecutionClientFactory for InteractiveBrokersExecutionClientFactory {\n    fn create(\n        &self,\n        trader_id: TraderId,\n        name: &str,\n        config: &dyn ClientConfig,\n        cache: CacheView,\n    ) -> anyhow::Result<Box<dyn ExecutionClient>> {\n        let mut ib_config = config\n            .as_any()\n            .downcast_ref::<InteractiveBrokersExecutionClientConfig>()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Invalid config type for InteractiveBrokersExecutionClientFactory. Expected InteractiveBrokersExecutionClientConfig, was {config:?}\",\n                )\n            })?\n            .clone();\n\n        let account_id = if let Some(account_id) = ib_config.account_id.as_deref() {\n            resolve_account_id(name, account_id)?\n        } else {\n            AccountId::from(\"IB-001\")\n        };\n        ib_config.account_id = Some(account_id.to_string());\n\n        let instrument_provider = Arc::new(InteractiveBrokersInstrumentProvider::new(\n            ib_config.instrument_provider.clone(),\n        ));\n        seed_provider_from_cache(&instrument_provider, &cache);\n\n        let core = ExecutionClientCore::new(","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/factories.rs#L141-L177","documentation":"InteractiveBrokersExecutionClientFactory::create downcasts the provided generic client config to InteractiveBrokersExecutionClientConfig and fails with this error if the concrete type is anything else. This prevents an execution client (which places orders) from being built with an incompatible config object.","triggerScenarios":"Building an execution client via InteractiveBrokersExecutionClientFactory with a config that is not InteractiveBrokersExecutionClientConfig — e.g. the data client config, another adapter's config, or a custom type.","commonSituations":"Swapped config arguments when registering both IB data and execution clients; refactoring that renamed/replaced the config type without updating factory wiring; instantiating a shared base config struct instead of the execution-specific one.","solutions":["Pass an InteractiveBrokersExecutionClientConfig instance to this factory's create.","Read the `config:?` dump in the message to see which wrong type was supplied.","Ensure each client registration pairs the correct config with the correct factory (data config -> data factory, exec config -> exec factory).","If a custom config is needed, build a plain InteractiveBrokersExecutionClientConfig rather than an unrelated type."],"exampleFix":"// before\nlet config = InteractiveBrokersDataClientConfig::default();\nexec_engine.register_client(factory.create(\"IB\", config, cache)?)?;\n// after\nlet config = InteractiveBrokersExecutionClientConfig::default();\nexec_engine.register_client(factory.create(\"IB\", config, cache)?)?;","handlingStrategy":"type-guard","validationCode":"// ensure concrete type before handing to factory\nlet cfg: &InteractiveBrokersExecutionClientConfig = config\n    .as_any()\n    .downcast_ref::<InteractiveBrokersExecutionClientConfig>()\n    .expect(\"exec factory requires InteractiveBrokersExecutionClientConfig\");","typeGuard":"fn is_ib_exec_config(config: &dyn ClientConfig) -> bool {\n    config.as_any().downcast_ref::<InteractiveBrokersExecutionClientConfig>().is_some()\n}","tryCatchPattern":"match factory.create(name, config, cache) {\n    Ok(client) => register(client),\n    Err(e) if e.to_string().contains(\"Invalid config type for InteractiveBrokersExecutionClientFactory\") => {\n        panic!(\"wiring bug: wrong config passed to IB exec factory: {e}\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep data and exec client construction in separate, clearly named helpers","Assert config types in tests that build the trading node","Never reuse one config variable for both data and exec client registration"],"tags":["config","factory","downcast"],"backgroundTag":"config-type-mismatch","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"}