{"record":{"id":"dd5b83d792b8aa66","repo":"nautechsystems/nautilus_trader","slug":"invalid-config-type-for-okxdataclientfactory-expe","errorCode":null,"errorMessage":"Invalid config type for OKXDataClientFactory. Expected OKXDataClientConfig, was {config:?}","messagePattern":"Invalid config type for OKXDataClientFactory\\. Expected OKXDataClientConfig, was (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/factories.rs","lineNumber":92,"sourceCode":"impl Default for OKXDataClientFactory {\n    fn default() -> Self {\n        Self::new()\n    }\n}\n\nimpl DataClientFactory for OKXDataClientFactory {\n    fn create(\n        &self,\n        name: &str,\n        config: &dyn ClientConfig,\n        _cache: CacheView,\n        _clock: Rc<RefCell<dyn Clock>>,\n    ) -> anyhow::Result<Box<dyn DataClient>> {\n        let okx_config = config\n            .as_any()\n            .downcast_ref::<OKXDataClientConfig>()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Invalid config type for OKXDataClientFactory. Expected OKXDataClientConfig, was {config:?}\",\n                )\n            })?\n            .clone();\n\n        let client_id = ClientId::from(name);\n        let client = OKXDataClient::new(client_id, okx_config)?;\n        Ok(Box::new(client))\n    }\n\n    fn name(&self) -> &'static str {\n        OKX\n    }\n\n    fn config_type(&self) -> &'static str {\n        \"OKXDataClientConfig\"\n    }\n}","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/factories.rs#L74-L110","documentation":"OKXDataClientFactory::create only accepts a config object that downcasts to OKXDataClientConfig. When the registered config type differs (wrong adapter config passed to the factory), the downcast fails and the factory refuses to construct a data client, echoing the actual config's debug representation.","triggerScenarios":"Calling OKXDataClientFactory::create with a ClientConfig that is not OKXDataClientConfig, e.g. a BinanceDataClientConfig, generic DataClientConfig, or deserialized config whose concrete type was lost.","commonSituations":"Mixing adapter configs when running multiple venues; loading client configs from JSON/TOML where the type tag is wrong; renaming or refactoring config structs across versions.","solutions":["Ensure the config passed for client name is constructed as OKXDataClientConfig (or deserialized into it).","Check the trader's client registration map so each factory name maps to the matching OKX config type.","Fix the config file/serialization so the concrete type tag identifies OKXDataClientConfig."],"exampleFix":"// before\nlet config = DataClientConfig::new(...) ; factory.create(name, config.boxed(), ...)\n// after\nlet config = OKXDataClientConfig::new(api_key, api_secret, passphrase);\nfactory.create(name, Box::new(config), ...);","handlingStrategy":"type-guard","validationCode":"fn is_okx_data_config(cfg: &dyn ClientConfig) -> bool {\n    cfg.as_any().downcast_ref::<OKXDataClientConfig>().is_some()\n}","typeGuard":"fn as_okx_data_config(cfg: &dyn ClientConfig) -> Option<&OKXDataClientConfig> {\n    cfg.as_any().downcast_ref::<OKXDataClientConfig>()\n}","tryCatchPattern":"match as_okx_data_config(config.as_ref()) {\n    Some(okx_cfg) => factory.create(name, config, clock, cache),\n    None => return Err(anyhow!(\"expected OKXDataClientConfig, got {config:?}\")),\n}","preventionTips":["Register each venue factory only with its matching config type.","When deserializing configs, use tagged enums keyed by venue so concrete types are preserved.","Add a unit test asserting factory/config pairing for every venue in your setup."],"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-14T00:17:10.932Z"}