nautechsystems/nautilus_trader · error · anyhow::Error

Invalid config type for InteractiveBrokersDataClientFactory.

Error message

Invalid config type for InteractiveBrokersDataClientFactory. Expected InteractiveBrokersDataClientConfig, was {config:?}

What it means

InteractiveBrokersDataClientFactory::create requires the generic client config passed down from the node to be exactly InteractiveBrokersDataClientConfig. It performs a downcast of the `dyn ClientConfig` and, if the concrete type differs, returns this error instead of building a client. This guards against wiring a wrong or incompatible config object to the IB data client factory.

Source

Thrown at crates/adapters/interactive_brokers/src/factories.rs:95

impl Default for InteractiveBrokersDataClientFactory {
    fn default() -> Self {
        Self::new()
    }
}

impl DataClientFactory for InteractiveBrokersDataClientFactory {
    fn create(
        &self,
        name: &str,
        config: &dyn ClientConfig,
        cache: CacheView,
        _clock: Rc<RefCell<dyn Clock>>,
    ) -> anyhow::Result<Box<dyn DataClient>> {
        let ib_config = config
            .as_any()
            .downcast_ref::<InteractiveBrokersDataClientConfig>()
            .ok_or_else(|| {
                anyhow::anyhow!(
                    "Invalid config type for InteractiveBrokersDataClientFactory. Expected InteractiveBrokersDataClientConfig, was {config:?}",
                )
            })?
            .clone();

        let instrument_provider = Arc::new(InteractiveBrokersInstrumentProvider::new(
            ib_config.instrument_provider.clone(),
        ));
        seed_provider_from_cache(&instrument_provider, &cache);
        let client = InteractiveBrokersDataClient::new(
            ClientId::from(name),
            ib_config,
            instrument_provider,
        )?;
        Ok(Box::new(client))
    }

    fn name(&self) -> &'static str {

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Pass an InteractiveBrokersDataClientConfig instance when creating the data client through this factory.
  2. Check the `config:?` debug dump in the message to identify the concrete type actually passed.
  3. If using a wrapper/subclass config, flatten it into a plain InteractiveBrokersDataClientConfig.
  4. Verify the factory registered in the client builder matches the config type (data factory for data config).

Example fix

// before
let config = InteractiveBrokersExecClientConfig::default();
data_engine.register_client(factory.create("IB", config)?)?;
// after
let config = InteractiveBrokersDataClientConfig::default();
data_engine.register_client(factory.create("IB", config)?)?;
Defensive patterns

Strategy: type-guard

Validate before calling

// ensure concrete type before handing to factory
let cfg: &InteractiveBrokersDataClientConfig = config
    .as_any()
    .downcast_ref::<InteractiveBrokersDataClientConfig>()
    .expect("data factory requires InteractiveBrokersDataClientConfig");

Type guard

fn is_ib_data_config(config: &dyn ClientConfig) -> bool {
    config.as_any().downcast_ref::<InteractiveBrokersDataClientConfig>().is_some()
}

Try / catch

match factory.create(name, config, clock) {
    Ok(client) => register(client),
    Err(e) if e.to_string().contains("Invalid config type for InteractiveBrokersDataClientFactory") => {
        panic!("wiring bug: wrong config passed to IB data factory: {e}");
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Building a data client via InteractiveBrokersDataClientFactory with any config other than InteractiveBrokersDataClientConfig (e.g. an execution client config, another adapter's config, or a custom config struct).

Common situations: Copy-pasting client factory wiring and passing the execution client's config to the data client factory; composing a node from a template where config types got swapped; a custom config type that merely resembles the IB config.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/b73e1d452aab0a1d. Report an issue: GitHub.