nautechsystems/nautilus_trader · error

Invalid config type for DeribitExecutionClientFactory. Expec

Error message

Invalid config type for DeribitExecutionClientFactory. Expected DeribitExecutionClientConfig, was {config:?}

What it means

DeribitExecutionClientFactory::create requires the config to be a DeribitExecutionClientConfig. It downcasts the type-erased ClientConfig; if the concrete type differs the downcast fails and this error is raised with the actual config's Debug output. It exists to catch wiring a non-execution (e.g. data-client) config into the execution factory.

Source

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

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

impl ExecutionClientFactory for DeribitExecutionClientFactory {
    fn create(
        &self,
        trader_id: TraderId,
        name: &str,
        config: &dyn ClientConfig,
        cache: CacheView,
    ) -> anyhow::Result<Box<dyn ExecutionClient>> {
        let deribit_config = config
            .as_any()
            .downcast_ref::<DeribitExecutionClientConfig>()
            .ok_or_else(|| {
                anyhow::anyhow!(
                    "Invalid config type for DeribitExecutionClientFactory. Expected DeribitExecutionClientConfig, was {config:?}",
                )
            })?
            .clone();

        // Deribit uses netting (derivatives only, no hedging)
        let oms_type = OmsType::Netting;
        let account_type = AccountType::Margin;

        let client_id = ClientId::from(name);
        let core = ExecutionClientCore::new(
            trader_id,
            client_id,
            *DERIBIT_VENUE,
            oms_type,
            deribit_config.account_id,
            account_type,
            None, // base_currency

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Pass a DeribitExecutionClientConfig to this factory; inspect the printed Debug type name in the message to confirm what was actually passed.
  2. Build the execution config explicitly (DeribitExecutionClientConfig::new(instrument_provider_config, ...)) and wire it only into DeribitExecutionClientFactory.
  3. In generic bootstrap code, match the config concrete type to the corresponding factory instead of passing every config to every factory.

Example fix

// before
let config = DeribitDataClientConfig::new(provider_config);
let exec = DeribitExecutionClientFactory.create(name, Rc::new(config), cache, clock)?;
// after
let config = DeribitExecutionClientConfig::new(provider_config);
let exec = DeribitExecutionClientFactory.create(name, Rc::new(config), cache, clock)?;
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Calling DeribitExecutionClientFactory::create(name, config, cache, ...) with any config other than DeribitExecutionClientConfig — most commonly a DeribitDataClientConfig or another venue's config.

Common situations: Duplicating data-client wiring for the execution client without changing the config type; bootstrapping all Deribit clients from one shared config; typos in generic bootstrap code that pass the wrong Rc'd config to the wrong factory.

Related errors


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