nautechsystems/nautilus_trader · error · anyhow::Error
Invalid config type for InteractiveBrokersExecutionClientFac
Error message
Invalid config type for InteractiveBrokersExecutionClientFactory. Expected InteractiveBrokersExecutionClientConfig, was {config:?} What it means
InteractiveBrokersExecutionClientFactory::create downcasts the provided generic client config to InteractiveBrokersExecutionClientConfig and fails with this error if the concrete type is anything else. This prevents an execution client (which places orders) from being built with an incompatible config object.
Source
Thrown at crates/adapters/interactive_brokers/src/factories.rs:159
#[must_use]
pub const fn new() -> Self {
Self
}
}
impl ExecutionClientFactory for InteractiveBrokersExecutionClientFactory {
fn create(
&self,
trader_id: TraderId,
name: &str,
config: &dyn ClientConfig,
cache: CacheView,
) -> anyhow::Result<Box<dyn ExecutionClient>> {
let mut ib_config = config
.as_any()
.downcast_ref::<InteractiveBrokersExecutionClientConfig>()
.ok_or_else(|| {
anyhow::anyhow!(
"Invalid config type for InteractiveBrokersExecutionClientFactory. Expected InteractiveBrokersExecutionClientConfig, was {config:?}",
)
})?
.clone();
let account_id = if let Some(account_id) = ib_config.account_id.as_deref() {
resolve_account_id(name, account_id)?
} else {
AccountId::from("IB-001")
};
ib_config.account_id = Some(account_id.to_string());
let instrument_provider = Arc::new(InteractiveBrokersInstrumentProvider::new(
ib_config.instrument_provider.clone(),
));
seed_provider_from_cache(&instrument_provider, &cache);
let core = ExecutionClientCore::new(View on GitHub (pinned to 18893faf8b)
Solutions
- Pass an InteractiveBrokersExecutionClientConfig instance to this factory's create.
- Read the `config:?` dump in the message to see which wrong type was supplied.
- Ensure each client registration pairs the correct config with the correct factory (data config -> data factory, exec config -> exec factory).
- If a custom config is needed, build a plain InteractiveBrokersExecutionClientConfig rather than an unrelated type.
Example fix
// before
let config = InteractiveBrokersDataClientConfig::default();
exec_engine.register_client(factory.create("IB", config, cache)?)?;
// after
let config = InteractiveBrokersExecutionClientConfig::default();
exec_engine.register_client(factory.create("IB", config, cache)?)?; Defensive patterns
Strategy: type-guard
Validate before calling
// ensure concrete type before handing to factory
let cfg: &InteractiveBrokersExecutionClientConfig = config
.as_any()
.downcast_ref::<InteractiveBrokersExecutionClientConfig>()
.expect("exec factory requires InteractiveBrokersExecutionClientConfig"); Type guard
fn is_ib_exec_config(config: &dyn ClientConfig) -> bool {
config.as_any().downcast_ref::<InteractiveBrokersExecutionClientConfig>().is_some()
} Try / catch
match factory.create(name, config, cache) {
Ok(client) => register(client),
Err(e) if e.to_string().contains("Invalid config type for InteractiveBrokersExecutionClientFactory") => {
panic!("wiring bug: wrong config passed to IB exec factory: {e}");
}
Err(e) => return Err(e),
} Prevention
- Keep data and exec client construction in separate, clearly named helpers
- Assert config types in tests that build the trading node
- Never reuse one config variable for both data and exec client registration
When it happens
Trigger: Building an execution client via InteractiveBrokersExecutionClientFactory with a config that is not InteractiveBrokersExecutionClientConfig — e.g. the data client config, another adapter's config, or a custom type.
Common situations: Swapped config arguments when registering both IB data and execution clients; refactoring that renamed/replaced the config type without updating factory wiring; instantiating a shared base config struct instead of the execution-specific one.
Related errors
- Invalid config type for BetfairDataClientFactory. Expected B
- Invalid config type for BetfairExecutionClientFactory. Expec
- Invalid config type for BitmexDataClientFactory. Expected Bi
- Invalid config type for BitmexExecutionClientFactory. Expect
- Invalid config type for BlockchainDataClientFactory. Expecte
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/33d4e92dbeb43074.
Report an issue: GitHub.