nautechsystems/nautilus_trader · error
Invalid config type for PolymarketExecutionClientFactory. Ex
Error message
Invalid config type for PolymarketExecutionClientFactory. Expected PolymarketExecutionClientConfig, was {config:?} What it means
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.
Source
Thrown at crates/adapters/polymarket/src/factories.rs:186
feature = "python",
pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.polymarket")
)]
#[derive(Debug, Clone)]
pub struct PolymarketExecutionClientFactory;
impl ExecutionClientFactory for PolymarketExecutionClientFactory {
fn create(
&self,
trader_id: TraderId,
name: &str,
config: &dyn ClientConfig,
cache: CacheView,
) -> anyhow::Result<Box<dyn ExecutionClient>> {
let polymarket_config = config
.as_any()
.downcast_ref::<PolymarketExecutionClientConfig>()
.ok_or_else(|| {
anyhow::anyhow!(
"Invalid config type for PolymarketExecutionClientFactory. Expected PolymarketExecutionClientConfig, was {config:?}",
)
})?
.clone();
let oms_type = OmsType::Netting;
let account_type = AccountType::Cash;
let client_id = ClientId::from(name);
let core = ExecutionClientCore::new(
trader_id,
client_id,
*POLYMARKET_VENUE,
oms_type,
polymarket_config.account_id,
account_type,
None, // base_currency
cache,View on GitHub (pinned to 18893faf8b)
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.
Example fix
// before
let client = exec_factory.create(data_config, cache).unwrap();
// after
let exec_config = config.as_any().downcast_ref::<PolymarketExecutionClientConfig>()
.expect("execution factory requires PolymarketExecutionClientConfig").clone();
let client = exec_factory.create(exec_config, cache).unwrap(); Defensive patterns
Strategy: type-guard
Validate before calling
fn is_polymarket_exec_config(config: &dyn ClientConfig) -> bool {
config.as_any().is::<PolymarketExecutionClientConfig>()
} Type guard
fn as_polymarket_exec_config(config: &dyn ClientConfig) -> Option<&PolymarketExecutionClientConfig> {
config.as_any().downcast_ref::<PolymarketExecutionClientConfig>()
} Try / catch
match config.as_any().downcast_ref::<PolymarketExecutionClientConfig>() {
Some(c) => factory.create(c.clone(), cache)?,
None => bail!("wrong config type for PolymarketExecutionClientFactory: {:?}", config),
} Prevention
- 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.
When it happens
Trigger: Calling PolymarketExecutionClientFactory::create with e.g. PolymarketDataClientConfig, a different adapter's ExecutionClientConfig, or any config not built via PolymarketExecutionClientConfig.
Common situations: 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.
Related errors
- Invalid config type for BlockchainDataClientFactory. Expecte
- Invalid config type for BlockchainExecutionClientFactory. Ex
- Invalid config type for BybitDataClientFactory. Expected Byb
- Invalid config type for BybitExecutionClientFactory. Expecte
- Invalid config type for DatabentoDataClientFactory. Expected
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/b50dfa8b6ca458ba.
Report an issue: GitHub.