{"record":{"id":"f576c47d9b7510fc","repo":"nautechsystems/nautilus_trader","slug":"invalid-config-type-for-binanceexecutionclientfact","errorCode":null,"errorMessage":"Invalid config type for BinanceExecutionClientFactory. Expected BinanceExecClientConfig, was {config:?}","messagePattern":"Invalid config type for BinanceExecutionClientFactory\\. Expected BinanceExecClientConfig, was (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/factories.rs","lineNumber":154,"sourceCode":"\nimpl Default for BinanceExecutionClientFactory {\n    fn default() -> Self {\n        Self::new()\n    }\n}\n\nimpl ExecutionClientFactory for BinanceExecutionClientFactory {\n    fn create(\n        &self,\n        name: &str,\n        config: &dyn ClientConfig,\n        cache: CacheView,\n    ) -> anyhow::Result<Box<dyn ExecutionClient>> {\n        let binance_config = config\n            .as_any()\n            .downcast_ref::<BinanceExecClientConfig>()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Invalid config type for BinanceExecutionClientFactory. Expected BinanceExecClientConfig, was {config:?}\",\n                )\n            })?\n            .clone();\n\n        let product_type = binance_config.product_type;\n\n        binance_config.validate()?;\n\n        match product_type {\n            BinanceProductType::Spot => {\n                // Spot uses cash account type and hedging OMS\n                let account_type = AccountType::Cash;\n                let oms_type = OmsType::Hedging;\n\n                let core = ExecutionClientCore::new(\n                    binance_config.trader_id,\n                    ClientId::from(name),","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/factories.rs#L136-L172","documentation":"BinanceExecutionClientFactory.create downcasts the incoming ClientConfig to BinanceExecClientConfig. Passing any other concrete type (e.g. BinanceDataClientConfig) makes the downcast fail and the error reports the actual type's Debug representation so the wiring mistake is visible.","triggerScenarios":"Calling BinanceExecutionClientFactory.create with a non-exec config object — swapped data/exec config arguments, or a generic harness that routes one config to both factories.","commonSituations":"Custom Rust wiring over the ExecutionClientFactory trait; integration tests that construct factories by hand; copy-pasted factory setup code where only the factory name was changed but not the config.","solutions":["Pass a BinanceExecClientConfig instance to BinanceExecutionClientFactory.create.","Inspect the {config:?} in the message to identify which type actually arrived.","Guard generic wiring with a config_type() check before calling create."],"exampleFix":"// before\nlet exec = BinanceExecutionClientFactory.create(name, &data_config, cache)?; // data config!\n\n// after\nlet exec = BinanceExecutionClientFactory.create(name, &exec_config, cache)?; // BinanceExecClientConfig","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn is_binance_exec_config(config: &dyn ClientConfig) -> bool {\n    config.as_any().downcast_ref::<BinanceExecClientConfig>().is_some()\n}","tryCatchPattern":"match BinanceExecutionClientFactory.create(name, config, cache) {\n    Err(e) if e.to_string().contains('Invalid config type') => {\n        return Err(anyhow::anyhow!(\n            'wiring error: {config:?} routed to the Binance exec factory'\n        ));\n    }\n    result => result,\n}","preventionTips":["Pair BinanceExecutionClientFactory only with BinanceExecClientConfig.","Log factory.config_type() alongside client registration in custom wiring.","Add a compile-time-typed helper that takes the concrete config type."],"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"}