{"record":{"id":"d7e88181bef6f2a9","repo":"nautechsystems/nautilus_trader","slug":"invalid-config-type-for-binanceexecutionclientfact-d7e881","errorCode":null,"errorMessage":"Invalid config type for BinanceExecutionClientFactory. Expected BinanceExecutionClientConfig, was {config:?}","messagePattern":"Invalid config type for BinanceExecutionClientFactory\\. Expected BinanceExecutionClientConfig, was (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/factories.rs","lineNumber":155,"sourceCode":"impl Default for BinanceExecutionClientFactory {\n    fn default() -> Self {\n        Self::new()\n    }\n}\n\nimpl ExecutionClientFactory for BinanceExecutionClientFactory {\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 binance_config = config\n            .as_any()\n            .downcast_ref::<BinanceExecutionClientConfig>()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Invalid config type for BinanceExecutionClientFactory. Expected BinanceExecutionClientConfig, 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                    trader_id,\n                    ClientId::from(name),","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/factories.rs#L137-L173","documentation":"The Binance execution client factory received a runtime config object whose concrete type is not BinanceExecutionClientConfig. It downcasts the generic config to the expected type via downcast_ref and fails with this message when the downcast returns None, so a Binance execution client can never be constructed from a mismatched config.","triggerScenarios":"Calling create() on BinanceExecutionClientFactory with a config that is a different client's config struct (e.g. BinanceDataClientConfig, BinanceFuturesExecutionClientConfig-style type, or a generic ClientConfig) passed in the config registry for the BINANCE_EXEC venue.","commonSituations":"Config typed for the Binance data client but registered for the exec client; mixing adapter versions where the exec config type was renamed; passing a deserialized generic config map instead of the concrete typed struct.","solutions":["Pass a BinanceExecutionClientConfig instance for the execution client factory registration","Check that the venue/config key you registered maps to the exec factory, not the data factory","Re-serialize/deserialize configs with the correct concrete type and keep adapter versions in sync","Log {config:?} in the message output to identify which type was actually supplied"],"exampleFix":"// before\nconfig: BinanceDataClientConfig { .. } // registered for exec factory\n// after\nlet exec_config = BinanceExecutionClientConfig {\n    api_key,\n    api_secret,\n    product_type: BinanceProductType::UsdTFuture,\n    ..Default::default()\n};\nfactory.create(exec_config, cache).await","handlingStrategy":"type-guard","validationCode":"fn is_binance_exec_config(cfg: &dyn ClientConfig) -> bool {\n    cfg.as_any().downcast_ref::<BinanceExecutionClientConfig>().is_some()\n}","typeGuard":"fn as_binance_exec_config(cfg: &dyn ClientConfig) -> Option<&BinanceExecutionClientConfig> {\n    cfg.as_any().downcast_ref::<BinanceExecutionClientConfig>()\n}","tryCatchPattern":"match factory.create(config.clone(), cache).await {\n    Ok(client) => client,\n    Err(e) if e.to_string().contains(\"Invalid config type\") => {\n        return Err(anyhow!(\"wrong config type for exec factory: {}\", e));\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep data-client and exec-client configs in separate, clearly named config structs","Assert the concrete config type in unit tests before wiring factories","Log config type names at startup to catch mismatches early"],"tags":["config","downcast","type-mismatch","binance"],"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"}