{"record":{"id":"0dcb33f1ec6505d2","repo":"nautechsystems/nautilus_trader","slug":"invalid-config-type-for-axdataclientfactory-expec","errorCode":null,"errorMessage":"Invalid config type for AxDataClientFactory. Expected AxDataClientConfig, was {config:?}","messagePattern":"Invalid config type for AxDataClientFactory\\. Expected AxDataClientConfig, was (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/architect_ax/src/factories.rs","lineNumber":94,"sourceCode":"impl Default for AxDataClientFactory {\n    fn default() -> Self {\n        Self::new()\n    }\n}\n\nimpl DataClientFactory for AxDataClientFactory {\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 ax_config = config\n            .as_any()\n            .downcast_ref::<AxDataClientConfig>()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Invalid config type for AxDataClientFactory. Expected AxDataClientConfig, was {config:?}\",\n                )\n            })?\n            .clone();\n\n        let client_id = ClientId::from(name);\n\n        let http_client = if ax_config.has_api_credentials() {\n            let credential =\n                Credential::resolve(ax_config.api_key.clone(), ax_config.api_secret.clone())\n                    .ok_or_else(|| anyhow::anyhow!(\"API credentials not configured\"))?;\n\n            AxHttpClient::with_credentials(\n                credential.api_key().to_string(),\n                credential.api_secret().to_string(),\n                Some(ax_config.http_base_url()),\n                None, // orders_base_url\n                ax_config.http_timeout_secs,","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/architect_ax/src/factories.rs#L76-L112","documentation":"AxDataClientFactory::create downcasts the passed &dyn ClientConfig to AxDataClientConfig; failure means the caller handed the wrong config object type. The message prints what was actually received. This only happens when wiring factories manually or through a custom FactoryRouter - the standard Nautilus TraderNode path always pairs the right config with the right factory.","triggerScenarios":"Calling AxDataClientFactory.create() with an AxExecClientConfig, a config from another adapter, or a custom ClientConfig implementation; reusing one config object for both the data and execution factories in hand-rolled Rust wiring.","commonSituations":"Custom tooling that registers factories generically over Vec<Box<dyn ClientConfig>>; copy-paste wiring code where the data and exec configs were swapped.","solutions":["Pass an AxDataClientConfig (or its Python twin) to AxDataClientFactory::create","Use TradingNode with the AX routing config instead of manual factory calls, which enforces the pairing","Check the {config:?} payload in the message to see which config actually arrived"],"exampleFix":"// before\nlet data_client = AxDataClientFactory.create(\n    \"AX\",\n    &exec_config, // AxExecClientConfig -> downcast fails\n    cache_view,\n    clock,\n)?;\n// after\nlet data_client = AxDataClientFactory.create(\n    \"AX\",\n    &AxDataClientConfig::default(),\n    cache_view,\n    clock,\n)?;","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Rust\nfn is_ax_data_config(cfg: &dyn ClientConfig) -> bool {\n    cfg.as_any().downcast_ref::<AxDataClientConfig>().is_some()\n}\n# Python\nisinstance(config, AxDataClientConfig)","tryCatchPattern":"match AxDataClientFactory.create(name, config, view, clock) {\n    Err(e) if e.to_string().contains(\"Invalid config type\") => {\n        panic_with_expected_type(e, \"AxDataClientConfig\");\n    }\n    r => r?,\n}","preventionTips":["Prefer TradingNode routing over manual factory.create() calls","Keep data and exec config construction adjacent in code with distinct variable names","Add a unit test asserting your wiring passes each factory its matching config type"],"tags":["architect-ax","factory","config","type-downcast","rust"],"backgroundTag":"invalid-config-type","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}