{"record":{"id":"4ef96d93c39f2997","repo":"nautechsystems/nautilus_trader","slug":"invalid-config-type-for-deriveexecutionclientfacto","errorCode":null,"errorMessage":"Invalid config type for DeriveExecutionClientFactory. Expected DeriveExecutionClientConfig, was {config:?}","messagePattern":"Invalid config type for DeriveExecutionClientFactory\\. Expected DeriveExecutionClientConfig, was (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/derive/src/factories.rs","lineNumber":144,"sourceCode":"impl Default for DeriveExecutionClientFactory {\n    fn default() -> Self {\n        Self::new()\n    }\n}\n\nimpl ExecutionClientFactory for DeriveExecutionClientFactory {\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 derive_config = config\n            .as_any()\n            .downcast_ref::<DeriveExecutionClientConfig>()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Invalid config type for DeriveExecutionClientFactory. Expected DeriveExecutionClientConfig, was {config:?}\",\n                )\n            })?\n            .clone();\n\n        // Derive perpetuals net per-subaccount; cash accounts are spot.\n        let oms_type = OmsType::Netting;\n        let account_type = AccountType::Margin;\n\n        let core = ExecutionClientCore::new(\n            trader_id,\n            ClientId::from(name),\n            *DERIVE_VENUE,\n            oms_type,\n            derive_config.account_id,\n            account_type,\n            None,\n            cache,","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/derive/src/factories.rs#L126-L162","documentation":"The DeriveExecutionClientFactory only accepts a config object that is (or wraps) a DeriveExecutionClientConfig. When downcasting the generic config fails, it throws this anyhow error naming the actual config type that was passed. It guards against wiring a client factory with the wrong adapter's config.","triggerScenarios":"Calling DeriveExecutionClientFactory::create with any config whose downcast_ref::<DeriveExecutionClientConfig>() returns None — e.g. a DeriveDataClientConfig, another exchange's ExecutionClientConfig, or a generically-built config.","commonSituations":"Copy-pasted factory wiring where the data-client config is reused for the exec client; building configs from TOML/JSON into a generic enum and passing the wrong variant; renaming/refactors that swap config structs.","solutions":["Pass a DeriveExecutionClientConfig instance to the factory's create call","Check that the config being constructed for this venue is the execution config, not the data config","If building configs dynamically, match on the variant and dispatch to the matching factory"],"exampleFix":"// before\nlet client = exec_factory.create(config, cache)?; // config is DeriveDataClientConfig\n// after\nlet exec_config = DeriveExecutionClientConfig::new(trader_id, account_id, ...);\nlet client = exec_factory.create(Box::new(exec_config), cache)?;","handlingStrategy":"type-guard","validationCode":"fn is_derive_exec_config(config: &dyn ClientConfig) -> bool { config.as_any().downcast_ref::<DeriveExecutionClientConfig>().is_some() }","typeGuard":"fn as_derive_exec_config(config: &dyn ClientConfig) -> Option<&DeriveExecutionClientConfig> { config.as_any().downcast_ref::<DeriveExecutionClientConfig>() }","tryCatchPattern":"match as_derive_exec_config(config.as_ref()) { Some(c) => build(c), None => return Err(anyhow!(\"expected DeriveExecutionClientConfig, check factory wiring\")) }","preventionTips":["Pair each venue's exec factory with its own exec config type in client-builder code","Add a unit test per factory asserting wrong-config rejection","Keep config construction and factory registration adjacent in the same module"],"tags":["rust","config","adapter","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-14T05:17:10.506Z"}