{"record":{"id":"9328e26639eaac78","repo":"nautechsystems/nautilus_trader","slug":"invalid-config-type-for-okxexecutionclientfactory","errorCode":null,"errorMessage":"Invalid config type for OKXExecutionClientFactory. Expected OKXExecutionClientConfig, was {config:?}","messagePattern":"Invalid config type for OKXExecutionClientFactory\\. Expected OKXExecutionClientConfig, was (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/factories.rs","lineNumber":150,"sourceCode":"impl Default for OKXExecutionClientFactory {\n    fn default() -> Self {\n        Self::new()\n    }\n}\n\nimpl ExecutionClientFactory for OKXExecutionClientFactory {\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 okx_config = config\n            .as_any()\n            .downcast_ref::<OKXExecutionClientConfig>()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Invalid config type for OKXExecutionClientFactory. Expected OKXExecutionClientConfig, was {config:?}\",\n                )\n            })?\n            .clone();\n\n        let has_derivatives = okx_config.instrument_types.iter().any(|t| {\n            matches!(\n                t,\n                OKXInstrumentType::Swap | OKXInstrumentType::Futures | OKXInstrumentType::Option\n            )\n        });\n\n        let account_type = if okx_config.use_spot_margin || has_derivatives {\n            AccountType::Margin\n        } else {\n            AccountType::Cash\n        };\n","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/factories.rs#L132-L168","documentation":"OKXExecutionClientFactory::create only accepts configs downcastable to OKXExecutionClientConfig. Any other config type fails the downcast and produces this error with the offending config's debug dump. This guards against wiring a non-OKX execution config into the OKX factory.","triggerScenarios":"Calling OKXExecutionClientFactory::create with a config that is not OKXExecutionClientConfig, such as another venue's ExecutionClientConfig or a wrongly-typed deserialized config.","commonSituations":"Copy-pasting factory wiring across adapters; config files where the execution client section specifies the wrong type; multi-venue setups with mismatched factory/config registration.","solutions":["Construct the config as OKXExecutionClientConfig including instrument_types and required credentials.","Verify the execution factory registration pairs the OKX factory with the OKX config type.","Correct the config serialization so the concrete type resolves to OKXExecutionClientConfig."],"exampleFix":"// before\nlet cfg = ExecutionClientConfig::default(); factory.create(name, cfg, clock, cache)\n// after\nlet cfg = OKXExecutionClientConfig::new(...).with_instrument_types(vec![OKXInstrumentType::Spot]);\nfactory.create(name, Box::new(cfg), clock, cache);","handlingStrategy":"type-guard","validationCode":"fn is_okx_exec_config(cfg: &dyn ClientConfig) -> bool {\n    cfg.as_any().downcast_ref::<OKXExecutionClientConfig>().is_some()\n}","typeGuard":"fn as_okx_exec_config(cfg: &dyn ClientConfig) -> Option<&OKXExecutionClientConfig> {\n    cfg.as_any().downcast_ref::<OKXExecutionClientConfig>()\n}","tryCatchPattern":"match as_okx_exec_config(config.as_ref()) {\n    Some(okx_cfg) => factory.create(name, config, clock, cache),\n    None => return Err(anyhow!(\"expected OKXExecutionClientConfig, got {config:?}\")),\n}","preventionTips":["Construct execution configs explicitly as OKXExecutionClientConfig with instrument_types set.","Avoid sharing one generic config type across venues.","Test factory wiring for all execution clients in CI."],"tags":["rust","config","downcast","okx"],"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"}