nautechsystems/nautilus_trader · error · anyhow::Error

Invalid config type for KrakenDataClientFactory. Expected Kr

Error message

Invalid config type for KrakenDataClientFactory. Expected KrakenDataClientConfig, was {config:?}

What it means

Raised in `KrakenDataClientFactory::create` when the generic `config` handed to the factory cannot be downcast to `KrakenDataClientConfig`. The factory is type-agnostic and relies on the caller passing the exact concrete config type registered for Kraken; anything else fails the `downcast_ref` and this anyhow error names both the expected type and the actual config's Debug representation.

Source

Thrown at crates/adapters/kraken/src/factories.rs:86

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

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

        kraken_config.validate()?;

        let client_id = ClientId::from(name);

        match kraken_config.product_type {
            KrakenProductType::Spot => {
                let client = KrakenSpotDataClient::new(client_id, kraken_config)?;
                Ok(Box::new(client))
            }
            KrakenProductType::Futures => {
                let client = KrakenFuturesDataClient::new(client_id, kraken_config)?;
                Ok(Box::new(client))
            }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Pass a `KrakenDataClientConfig` instance to the data client factory.
  2. Check the `{config:?}` in the message to see which wrong type was actually supplied.
  3. Ensure the data factory is registered with its matching config type and the execution factory with `KrakenExecClientConfig`.
  4. If constructing configs dynamically, downcast/verify the concrete type before calling `create`.

Example fix

// before
let data_config = KrakenExecClientConfig { ... };
data_factory.create(name, config, Some(venue), Some(instruments), cache, clock)?;

// after
let data_config = KrakenDataClientConfig { ... };
data_factory.create(name, config, Some(venue), Some(instruments), cache, clock)?;
Defensive patterns

Strategy: type-guard

Validate before calling

// Rust
fn is_kraken_data_config(config: &dyn ClientConfig) -> bool {
    config.as_any().downcast_ref::<KrakenDataClientConfig>().is_some()
}

Type guard

fn as_kraken_data_config(config: &dyn ClientConfig) -> Option<&KrakenDataClientConfig> {
    config.as_any().downcast_ref::<KrakenDataClientConfig>()
}

Try / catch

match as_kraken_data_config(config) {
    Some(kraken_config) => data_factory.create(name, config, ...)?,
    None => anyhow::bail!("expected KrakenDataClientConfig for KrakenDataClientFactory"),
}

Prevention

When it happens

Trigger: Registering or invoking `KrakenDataClientFactory.create` with a config of another type — e.g. `KrakenExecClientConfig`, a different adapter's data config, or a plain/generic client config object.

Common situations: Copy-pasting factory wiring between Kraken data and execution clients and passing the wrong config; registering the factory under a client name whose config type is mismatched in a custom node setup; version changes where config types were renamed/split.

Related errors


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