nautechsystems/nautilus_trader · error · anyhow::Error

Failed to register DEX exchange: {e}

Error message

Failed to register DEX exchange: {e}

What it means

Wraps any error returned by `BlockchainDataClientCore::register_dex_exchange` when the `sync dex` CLI command tries to register a DEX (e.g. Uniswap-v3) on the blockchain data client. Registration involves on-chain contract resolution and cache/database setup over the node RPC, so any RPC, network, unsupported-DEX, or database failure surfaces here under this message. The CLI aborts the whole sync via `?`.

Source

Thrown at crates/cli/src/blockchain/sync.rs:115

    log::info!("Using RPC HTTP URL: '{masked_url}'");

    let config = BlockchainDataClientConfig::builder()
        .chain(Arc::new(chain.to_owned()))
        .dex_ids(vec![dex_type])
        .http_rpc_url(rpc_http_url.into())
        .maybe_multicall_calls_per_rpc_request(multicall_calls_per_rpc_request)
        .use_hypersync_for_live_data(true)
        .postgres_cache_database_config(postgres_connect_options)
        .build();
    let cancellation_token = tokio_util::sync::CancellationToken::new();
    let mut data_client = BlockchainDataClientCore::new(config, None, None, cancellation_token);
    data_client.initialize_cache_database().await;

    data_client.cache.initialize_chain().await;
    data_client
        .register_dex_exchange(dex_type)
        .await
        .map_err(|e| anyhow::anyhow!("Failed to register DEX exchange: {e}"))?;
    // We want to have full pool sync, so from 0 to last.
    data_client
        .sync_exchange_pools(&dex_type, 0, None, reset)
        .await
        .map_err(|e| anyhow::anyhow!("Failed to sync pools: {e}"))?;

    Ok(())
}

pub(crate) async fn run_sync_blocks(
    chain: String,
    from_block: Option<u64>,
    to_block: Option<u64>,
    database: DatabaseConfig,
) -> anyhow::Result<()> {
    let chain = Chain::from_chain_name(&chain)
        .ok_or_else(|| anyhow::anyhow!("Invalid chain name: {chain}"))?;
    let chain = Arc::new(chain.to_owned());

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Verify the node RPC endpoint is running, reachable, and fully synced before retrying.
  2. Check the dex_type argument matches a DEX supported by the blockchain adapter (e.g. exact name/casing expected by the adapter).
  3. Confirm the --chain value matches the chain the node is connected to and that the DEX is deployed there.
  4. Check the cache/Postgres database config is correct and the database is reachable.
  5. Run with RUST_LOG=debug to see the underlying error embedded in `{e}` and address it directly.

Example fix

// before
"sync dex --dex-type uniswapv2 --chain arbitrum"   # node on mainnet, chain mismatch
// after
"sync dex --dex-type uniswap-v3 --chain ethereum --url http://localhost:8545"
Defensive patterns

Strategy: try-catch

Validate before calling

// before running: check node reachability
let status = reqwest::get(format!("{url}/health")).await;
assert!(status.is_ok(), "node RPC unreachable at {url}");
// and confirm dex_type is one the adapter supports

Try / catch

match run_sync_dex(...).await {
    Ok(()) => info!("DEX exchange registered"),
    Err(e) if e.to_string().contains("Failed to register DEX exchange") => {
        eprintln!("RPC/registration failed: {e:#}; check node URL, dex_type, and DB config");
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling `nautilus blockchain sync dex` (run_sync_dex) where the underlying node RPC is unreachable or errors, the configured provider URL/chain is wrong, the dex_type is not supported by the adapter, or the cache database cannot be initialized for the exchange.

Common situations: Running against a local Ethereum node that is not started or not synced; pointing at a chain that does not host the DEX; typos in the DEX name argument; Postgres/cache not reachable; RPC rate limits or timeouts during factory/contract lookups.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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