{"record":{"id":"b50dfa8b6ca458ba","repo":"nautechsystems/nautilus_trader","slug":"invalid-config-type-for-polymarketexecutionclientf","errorCode":null,"errorMessage":"Invalid config type for PolymarketExecutionClientFactory. Expected PolymarketExecutionClientConfig, was {config:?}","messagePattern":"Invalid config type for PolymarketExecutionClientFactory\\. Expected PolymarketExecutionClientConfig, was (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/factories.rs","lineNumber":186,"sourceCode":"    feature = \"python\",\n    pyo3_stub_gen::derive::gen_stub_pyclass(module = \"nautilus_trader.adapters.polymarket\")\n)]\n#[derive(Debug, Clone)]\npub struct PolymarketExecutionClientFactory;\n\nimpl ExecutionClientFactory for PolymarketExecutionClientFactory {\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 polymarket_config = config\n            .as_any()\n            .downcast_ref::<PolymarketExecutionClientConfig>()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Invalid config type for PolymarketExecutionClientFactory. Expected PolymarketExecutionClientConfig, was {config:?}\",\n                )\n            })?\n            .clone();\n\n        let oms_type = OmsType::Netting;\n        let account_type = AccountType::Cash;\n\n        let client_id = ClientId::from(name);\n        let core = ExecutionClientCore::new(\n            trader_id,\n            client_id,\n            *POLYMARKET_VENUE,\n            oms_type,\n            polymarket_config.account_id,\n            account_type,\n            None, // base_currency\n            cache,","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/factories.rs#L168-L204","documentation":"PolymarketExecutionClientFactory::create only accepts a config object of concrete type PolymarketExecutionClientConfig. It attempts a downcast of the passed trait-object config and returns this anyhow error when the downcast fails, meaning a config of another client's type (or the data-client config) was supplied to the execution factory.","triggerScenarios":"Calling PolymarketExecutionClientFactory::create with e.g. PolymarketDataClientConfig, a different adapter's ExecutionClientConfig, or any config not built via PolymarketExecutionClientConfig.","commonSituations":"Copy-pasting factory wiring between data and execution client setup, registering the wrong config with a generic factory registry, or swapping config structs after a refactor.","solutions":["Construct and pass a PolymarketExecutionClientConfig (parse it from your config section with its deserializer).","Check that the factory registration pairs PolymarketExecutionClientFactory with PolymarketExecutionClientConfig, not the data client's config.","If using a generic config enum/registry, verify which variant is routed to the execution factory before calling create."],"exampleFix":"// before\nlet client = exec_factory.create(data_config, cache).unwrap();\n// after\nlet exec_config = config.as_any().downcast_ref::<PolymarketExecutionClientConfig>()\n    .expect(\"execution factory requires PolymarketExecutionClientConfig\").clone();\nlet client = exec_factory.create(exec_config, cache).unwrap();","handlingStrategy":"type-guard","validationCode":"fn is_polymarket_exec_config(config: &dyn ClientConfig) -> bool {\n    config.as_any().is::<PolymarketExecutionClientConfig>()\n}","typeGuard":"fn as_polymarket_exec_config(config: &dyn ClientConfig) -> Option<&PolymarketExecutionClientConfig> {\n    config.as_any().downcast_ref::<PolymarketExecutionClientConfig>()\n}","tryCatchPattern":"match config.as_any().downcast_ref::<PolymarketExecutionClientConfig>() {\n    Some(c) => factory.create(c.clone(), cache)?,\n    None => bail!(\"wrong config type for PolymarketExecutionClientFactory: {:?}\", config),\n}","preventionTips":["Always build execution client configs via PolymarketExecutionClientConfig, never reuse the data client's config struct.","Pair factory and config types in one registration site so they cannot drift.","Add a unit test per factory asserting it rejects the wrong config type."],"tags":["rust","config","downcast","polymarket"],"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"}