{"record":{"id":"be6cf270158c1a3b","repo":"nautechsystems/nautilus_trader","slug":"invalid-config-type-for-axexecutionclientfactory-be6cf2","errorCode":null,"errorMessage":"Invalid config type for AxExecutionClientFactory. Expected AxExecutionClientConfig, was {config:?}","messagePattern":"Invalid config type for AxExecutionClientFactory\\. Expected AxExecutionClientConfig, was (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/architect_ax/src/factories.rs","lineNumber":204,"sourceCode":"impl Default for AxExecutionClientFactory {\n    fn default() -> Self {\n        Self::new()\n    }\n}\n\nimpl ExecutionClientFactory for AxExecutionClientFactory {\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 ax_config = config\n            .as_any()\n            .downcast_ref::<AxExecutionClientConfig>()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Invalid config type for AxExecutionClientFactory. Expected AxExecutionClientConfig, was {config:?}\",\n                )\n            })?\n            .clone();\n\n        // AX uses netting for perpetual futures\n        let oms_type = OmsType::Netting;\n        let account_type = AccountType::Margin;\n\n        let core = ExecutionClientCore::new(\n            trader_id,\n            ClientId::from(name),\n            *AX_VENUE,\n            oms_type,\n            ax_config.account_id,\n            account_type,\n            None, // base_currency\n            cache,","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/architect_ax/src/factories.rs#L186-L222","documentation":"AxExecutionClientFactory::create downcasts the generic config to `AxExecutionClientConfig`; any other config type causes this error, echoing the received config's debug output. Like its data-client sibling, it is a factory type guard.","triggerScenarios":"Calling `AxExecutionClientFactory.create(name, config, ...)` with a config that is not `AxExecutionClientConfig` — commonly an `AxDataClientConfig` or a generic/other-venue execution config.","commonSituations":"Swapping data/execution configs in a multi-adapter bootstrap; passing a shared base config struct; registering the AX execution factory under a name whose config block belongs to the data client.","solutions":["Pass an `AxExecutionClientConfig` to the execution factory.","Check the `{config:?}` text in the message to identify the wrongly passed type.","Ensure each venue config block is routed to its matching factory (data config -> data factory, execution config -> execution factory).","If using a builder/generic loader, add explicit per-factory config construction instead of reusing one struct."],"exampleFix":"// before\nlet exec_config = AxDataClientConfig { ... };\nfactory.create(name, exec_config, ...)?; // wrong type\n\n// after\nlet exec_config = AxExecutionClientConfig {\n    api_key: Some(api_key),\n    api_secret: Some(api_secret),\n    ..Default::default()\n};\nfactory.create(name, exec_config, ...)?;","handlingStrategy":"type-guard","validationCode":"// before calling the execution factory\nlet Some(_) = config.as_any().downcast_ref::<AxExecutionClientConfig>() else {\n    panic!(\"config passed to AxExecutionClientFactory must be AxExecutionClientConfig\");\n};","typeGuard":"fn as_ax_exec_config(config: &dyn Any) -> Option<&AxExecutionClientConfig> {\n    config.downcast_ref::<AxExecutionClientConfig>()\n}","tryCatchPattern":"match factory.create(name, config, cache, ...) {\n    Err(e) if e.to_string().contains(\"Invalid config type for AxExecutionClientFactory\") => {\n        return Err(anyhow::anyhow!(\"pass AxExecutionClientConfig to the execution factory: {e}\"));\n    }\n    other => other,\n}","preventionTips":["Keep data and execution config construction in separate, clearly named functions.","Route configs to factories via explicit type dispatch, not positional wiring.","Add a bootstrap unit test that builds both AX clients from real config structs.","Check the echoed `{config:?}` whenever this fires to spot the swapped type quickly."],"tags":["configuration","type-mismatch","factory","rust"],"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"}