{"record":{"id":"1c1a4791200365d9","repo":"nautechsystems/nautilus_trader","slug":"invalid-config-type-for-deribitdataclientfactory","errorCode":null,"errorMessage":"Invalid config type for DeribitDataClientFactory. Expected DeribitDataClientConfig, was {config:?}","messagePattern":"Invalid config type for DeribitDataClientFactory\\. Expected DeribitDataClientConfig, was (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/deribit/src/factories.rs","lineNumber":83,"sourceCode":"impl Default for DeribitDataClientFactory {\n    fn default() -> Self {\n        Self::new()\n    }\n}\n\nimpl DataClientFactory for DeribitDataClientFactory {\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 deribit_config = config\n            .as_any()\n            .downcast_ref::<DeribitDataClientConfig>()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Invalid config type for DeribitDataClientFactory. Expected DeribitDataClientConfig, was {config:?}\",\n                )\n            })?\n            .clone();\n\n        let client_id = ClientId::from(name);\n        let client = DeribitDataClient::new(client_id, deribit_config)?;\n        Ok(Box::new(client))\n    }\n\n    fn name(&self) -> &'static str {\n        DERIBIT\n    }\n\n    fn config_type(&self) -> &'static str {\n        \"DeribitDataClientConfig\"\n    }\n}","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/deribit/src/factories.rs#L65-L101","documentation":"DeribitDataClientFactory::create requires the passed config object to be a DeribitDataClientConfig. The factory performs a downcast_ref::<DeribitDataClientConfig>() on the type-erased ClientConfig; when the downcast returns None, it raises this anyhow error including the debug representation of the config actually received. This guards against wiring a config of the wrong client type into the factory.","triggerScenarios":"Calling DeribitDataClientFactory::create(name, config, ...) with a config whose concrete type is not DeribitDataClientConfig — e.g. a DeribitExecutionClientConfig, a config for another venue adapter, or any other object implementing the ClientConfig trait.","commonSituations":"Copying factory setup code from another exchange adapter and forgetting to swap the config type; constructing clients from a generic config registry/loop that iterates mixed configs; a refactor that renamed or split the config type so the old struct is still constructed.","solutions":["Construct a DeribitDataClientConfig (with correct instrument, testnet flag, credentials) and pass that to the factory instead of the current config.","Check the config value printed in the message: its Debug type name tells you exactly which struct was passed; swap it for DeribitDataClientConfig.","If iterating a mixed config collection, match on config type and dispatch each config to its matching factory before calling create()."],"exampleFix":"// before\nlet config = DeribitExecutionClientConfig::new();\nlet client = DeribitDataClientFactory.create(name, Rc::new(config), cache, clock)?;\n// after\nlet config = DeribitDataClientConfig::new(instrument_provider_config);\nlet client = DeribitDataClientFactory.create(name, Rc::new(config), cache, clock)?;","handlingStrategy":"type-guard","validationCode":"let Some(cfg) = config.as_any().downcast_ref::<DeribitDataClientConfig>() else {\n    return Err(anyhow::anyhow!(\"expected DeribitDataClientConfig, got {config:?}\"));\n};","typeGuard":"fn is_deribit_data_config(config: &dyn ClientConfig) -> bool {\n    config.as_any().is::<DeribitDataClientConfig>()\n}","tryCatchPattern":"match factory.create(name, config, cache, clock) {\n    Ok(client) => client,\n    Err(e) => { eprintln!(\"deribit data client init failed: {e:#}\"); return Err(e); }\n}","preventionTips":["Keep each config struct next to its factory call in the bootstrap code so the pairing is obvious.","In loops over configs, match on the concrete config type and route to the matching factory.","Unit-test the happy-path wiring of each client at startup (fail fast before live trading)."],"tags":["rust","config","downcast","deribit","factory"],"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"}