nautechsystems/nautilus_trader · error

Invalid config type for DeribitDataClientFactory. Expected D

Error message

Invalid config type for DeribitDataClientFactory. Expected DeribitDataClientConfig, was {config:?}

What it means

DeribitDataClientFactory::create requires the passed config object to be a DeribitDataClientConfig. The factory performs a downcast_ref::<DeribitDataClientConfig>() on the type-erased ClientConfig; when the downcast returns None, it raises this anyhow error including the debug representation of the config actually received. This guards against wiring a config of the wrong client type into the factory.

Source

Thrown at crates/adapters/deribit/src/factories.rs:83

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

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

        let client_id = ClientId::from(name);
        let client = DeribitDataClient::new(client_id, deribit_config)?;
        Ok(Box::new(client))
    }

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

    fn config_type(&self) -> &'static str {
        "DeribitDataClientConfig"
    }
}

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Construct a DeribitDataClientConfig (with correct instrument, testnet flag, credentials) and pass that to the factory instead of the current config.
  2. Check the config value printed in the message: its Debug type name tells you exactly which struct was passed; swap it for DeribitDataClientConfig.
  3. If iterating a mixed config collection, match on config type and dispatch each config to its matching factory before calling create().

Example fix

// before
let config = DeribitExecutionClientConfig::new();
let client = DeribitDataClientFactory.create(name, Rc::new(config), cache, clock)?;
// after
let config = DeribitDataClientConfig::new(instrument_provider_config);
let client = DeribitDataClientFactory.create(name, Rc::new(config), cache, clock)?;
Defensive patterns

Strategy: type-guard

Validate before calling

let Some(cfg) = config.as_any().downcast_ref::<DeribitDataClientConfig>() else {
    return Err(anyhow::anyhow!("expected DeribitDataClientConfig, got {config:?}"));
};

Type guard

fn is_deribit_data_config(config: &dyn ClientConfig) -> bool {
    config.as_any().is::<DeribitDataClientConfig>()
}

Try / catch

match factory.create(name, config, cache, clock) {
    Ok(client) => client,
    Err(e) => { eprintln!("deribit data client init failed: {e:#}"); return Err(e); }
}

Prevention

When it happens

Trigger: Calling DeribitDataClientFactory::create(name, config, ...) with a config whose concrete type is not DeribitDataClientConfig — e.g. a DeribitExecutionClientConfig, a config for another venue adapter, or any other object implementing the ClientConfig trait.

Common situations: Copying factory setup code from another exchange adapter and forgetting to swap the config type; constructing clients from a generic config registry/loop that iterates mixed configs; a refactor that renamed or split the config type so the old struct is still constructed.

Related errors


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