{"record":{"id":"ad3f15f55d523aef","repo":"nautechsystems/nautilus_trader","slug":"invalid-config-type-for-bybitexecutionclientfactor","errorCode":null,"errorMessage":"Invalid config type for BybitExecutionClientFactory. Expected BybitExecutionClientConfig, was {config:?}","messagePattern":"Invalid config type for BybitExecutionClientFactory\\. Expected BybitExecutionClientConfig, was (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/bybit/src/factories.rs","lineNumber":144,"sourceCode":"    #[must_use]\n    pub const fn new() -> Self {\n        Self\n    }\n}\n\nimpl ExecutionClientFactory for BybitExecutionClientFactory {\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 bybit_config = config\n            .as_any()\n            .downcast_ref::<BybitExecutionClientConfig>()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Invalid config type for BybitExecutionClientFactory. Expected BybitExecutionClientConfig, was {config:?}\",\n                )\n            })?\n            .clone();\n\n        // Default to Linear if product_types is empty (matches execution client behavior)\n        let product_types = if bybit_config.product_types.is_empty() {\n            vec![BybitProductType::Linear]\n        } else {\n            bybit_config.product_types.clone()\n        };\n\n        let has_derivatives = product_types.iter().any(|t| {\n            matches!(\n                t,\n                BybitProductType::Linear | BybitProductType::Inverse | BybitProductType::Option\n            )\n        });","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bybit/src/factories.rs#L126-L162","documentation":"The BybitExecutionClientFactory.create() cannot downcast the supplied config to BybitExecutionClientConfig. Each execution factory expects its own concrete config type; any other DynData/ExecutionClientConfig implementation fails the downcast_ref and the factory returns an anyhow error embedding the Debug repr of what was actually passed.","triggerScenarios":"Registering BybitExecutionClientFactory with a BybitDataClientConfig, a base ExecutionClientConfig, or another adapter's execution config; swapping config structs in code without updating the factory; config deserialization producing the wrong concrete type for the 'bybit' execution client.","commonSituations":"Mixed-venue live cluster configs where the execution client section was left as another exchange's config; refactors that renamed/merged config types; hand-built ClientConfig objects passed to the wrong factory.","solutions":["Read the {config:?} debug output to identify the config type actually supplied","Replace it with a properly constructed BybitExecutionClientConfig (including product_types, api credentials)","Verify the factory-to-config pairing in your live node/cluster config file","Rebuild any custom config wrappers so they serialize/deserialize as BybitExecutionClientConfig"],"exampleFix":"// before\nlet factory = BybitExecutionClientFactory::new();\nlet config = BybitDataClientConfig { api_key, api_secret, ..Default::default() };\nlet client = factory.create(\"BYBIT\", config, cache, clock)?;\n// after\nlet config = BybitExecutionClientConfig { api_key, api_secret, product_types: vec![BybitProductType::Linear], ..Default::default() };\nlet client = factory.create(\"BYBIT\", config, cache, clock)?;","handlingStrategy":"type-guard","validationCode":"fn ensure_bybit_exec_config(config: &dyn Any) -> Result<&BybitExecutionClientConfig, String> {\n    config.downcast_ref::<BybitExecutionClientConfig>()\n        .ok_or_else(|| \"expected BybitExecutionClientConfig\".to_string())\n}","typeGuard":"fn is_bybit_exec_config(cfg: &dyn ExecutionClientConfig) -> bool {\n    cfg.as_any().downcast_ref::<BybitExecutionClientConfig>().is_some()\n}","tryCatchPattern":"let client = factory.create(name, config, cache, clock)\n    .map_err(|e| anyhow::anyhow!(\"Bybit exec client init failed: {e}\"))?;","preventionTips":["Use typed builders (generics) so the wrong config type cannot compile","Audit mixed-venue cluster configs when copying between environments","Unit-test factory creation with the exact config type"],"tags":["rust","config","downcast","bybit"],"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"}