{"record":{"id":"a80ad553613e3e7e","repo":"nautechsystems/nautilus_trader","slug":"invalid-config-type-for-binancedataclientfactory","errorCode":null,"errorMessage":"Invalid config type for BinanceDataClientFactory. Expected BinanceDataClientConfig, was {config:?}","messagePattern":"Invalid config type for BinanceDataClientFactory\\. Expected BinanceDataClientConfig, was (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/factories.rs","lineNumber":80,"sourceCode":"impl Default for BinanceDataClientFactory {\n    fn default() -> Self {\n        Self::new()\n    }\n}\n\nimpl DataClientFactory for BinanceDataClientFactory {\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 binance_config = config\n            .as_any()\n            .downcast_ref::<BinanceDataClientConfig>()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Invalid config type for BinanceDataClientFactory. Expected BinanceDataClientConfig, was {config:?}\",\n                )\n            })?\n            .clone();\n\n        let client_id = ClientId::from(name);\n\n        binance_config.validate()?;\n\n        let product_type = binance_config.product_type;\n\n        match product_type {\n            BinanceProductType::Spot => {\n                let client = BinanceSpotDataClient::new(client_id, binance_config)?;\n                Ok(Box::new(client))\n            }\n            BinanceProductType::UsdM | BinanceProductType::CoinM => {\n                let client =","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/factories.rs#L62-L98","documentation":"BinanceDataClientFactory.create downcasts the generic ClientConfig it receives to BinanceDataClientConfig; when a different config type is passed (e.g. BinanceExecClientConfig, a stub, or a dynamically-built config from another adapter), the downcast returns None and this error names the actual type via its Debug output.","triggerScenarios":"Registering BinanceDataClientFactory with a config object that is not BinanceDataClientConfig — for example swapping the data/exec config arguments in a factory wiring layer, or a custom ClientConfig implementation passed through a generic framework path.","commonSituations":"Building custom infrastructure on top of the factory traits (Rust users); passing an exec config where a data config belongs; a serde round-trip that reconstructed the config as the wrong concrete type.","solutions":["Pass a BinanceDataClientConfig instance to BinanceDataClientFactory.create (the config_type() name check helps log mismatches).","Check the error's {config:?} Debug output to see which concrete type was actually supplied.","If driving factories generically, dispatch on config_type() == stringify!(BinanceDataClientConfig) before calling create."],"exampleFix":"// before\nlet client = BinanceDataClientFactory.create(name, &exec_config, cache, clock)?; // exec config!\n\n// after\nlet client = BinanceDataClientFactory.create(name, &data_config, cache, clock)?; // BinanceDataClientConfig","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn is_binance_data_config(config: &dyn ClientConfig) -> bool {\n    config.as_any().downcast_ref::<BinanceDataClientConfig>().is_some()\n}","tryCatchPattern":"match BinanceDataClientFactory.create(name, config, cache, clock) {\n    Err(e) if e.to_string().contains('Invalid config type') => {\n        return Err(anyhow::anyhow!(\n            'wiring error: {config:?} routed to the Binance data factory'\n        ));\n    }\n    result => result,\n}","preventionTips":["Route configs by factory.config_type() before calling create.","Keep data and exec configs in separately named variables at call sites.","In tests, construct the exact config type each factory documents."],"tags":["binance","factory","downcast","config-type","internal-api"],"backgroundTag":"invalid-config-type","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}