{"record":{"id":"816f71dbdee491bd","repo":"nautechsystems/nautilus_trader","slug":"invalid-config-type-for-polymarketdataclientfactor","errorCode":null,"errorMessage":"Invalid config type for PolymarketDataClientFactory. Expected PolymarketDataClientConfig, was {config:?}","messagePattern":"Invalid config type for PolymarketDataClientFactory\\. Expected PolymarketDataClientConfig, was (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/factories.rs","lineNumber":77,"sourceCode":"    feature = \"python\",\n    pyo3_stub_gen::derive::gen_stub_pyclass(module = \"nautilus_trader.adapters.polymarket\")\n)]\n#[derive(Debug, Clone)]\npub struct PolymarketDataClientFactory;\n\nimpl DataClientFactory for PolymarketDataClientFactory {\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 polymarket_config = config\n            .as_any()\n            .downcast_ref::<PolymarketDataClientConfig>()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Invalid config type for PolymarketDataClientFactory. Expected PolymarketDataClientConfig, was {config:?}\",\n                )\n            })?;\n\n        Ok(Box::new(Self::create_client(name, polymarket_config)?))\n    }\n\n    fn name(&self) -> &'static str {\n        POLYMARKET\n    }\n\n    fn config_type(&self) -> &'static str {\n        \"PolymarketDataClientConfig\"\n    }\n}\n\nimpl PolymarketDataClientFactory {\n    fn create_client(","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/factories.rs#L59-L95","documentation":"Raised in `PolymarketDataClientFactory::create` when the supplied config cannot be downcast to `PolymarketDataClientConfig`. The factory uses `config.as_any().downcast_ref::<PolymarketDataClientConfig>()` and errors if the caller passed an exec-client config (or any other concrete config type) to the data-client factory. The message includes the Debug representation of the unexpected config for diagnosis.","triggerScenarios":"Registering/instantiating the data client factory with PolymarketExecClientConfig (or an unrelated config) instead of PolymarketDataClientConfig; wiring configs to factories in the wrong order in a node/trading setup script.","commonSituations":"Copy-paste mistakes when building both exec and data clients; YAML/JSON config parsed into the wrong concrete type; refactors renaming config structs so an old type still compiles but maps to the wrong factory.","solutions":["Pass a PolymarketDataClientConfig to the data-client factory (and PolymarketExecClientConfig to the exec factory)","Check the node/boot script for swapped factory-config pairings","Inspect the printed config Debug output to see which type was actually passed"],"exampleFix":"// before\nlet data_client = data_factory.create(name, exec_config, ...)?;\n// after\nlet data_client = data_factory.create(name, PolymarketDataClientConfig { .. }, ...)?;","handlingStrategy":"type-guard","validationCode":"let ok = config.as_any().downcast_ref::<PolymarketDataClientConfig>().is_some();\nif !ok { return Err(anyhow!(\"expected PolymarketDataClientConfig\")); }","typeGuard":"fn as_data_config<'a>(cfg: &'a dyn AnyConfig) -> Option<&'a PolymarketDataClientConfig> {\n    cfg.as_any().downcast_ref::<PolymarketDataClientConfig>()\n}","tryCatchPattern":"match data_factory.create(name, config, clock).await {\n    Err(e) if e.to_string().contains(\"Invalid config type for PolymarketDataClientFactory\") => {\n        // log which config type was passed (from the Debug in the message) and fix wiring\n    }\n    other => other,\n}","preventionTips":["Pair each factory with its matching config type in boot scripts","Add startup assertions on concrete config types before factory calls","Keep exec/data config construction in clearly separated code paths"],"tags":["polymarket","config","factory","downcast"],"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"}