nautechsystems/nautilus_trader · error · anyhow::Error

Invalid ticker format '{ticker}', expected 'BASE-QUOTE' (e.g

Error message

Invalid ticker format '{ticker}', expected 'BASE-QUOTE' (e.g., 'BTC-USD')

What it means

dYdX market tickers must be exactly two non-empty segments joined by a hyphen (`BASE-QUOTE`). `validate_ticker_format` splits on `-` and throws this error when the split does not yield exactly two parts.

Source

Thrown at crates/adapters/dydx/src/http/parse.rs:154

    let close = Price::from_decimal_dp(candle.close, price_precision)
        .context("failed to parse candle close price")?;
    let volume = Quantity::from_decimal_dp(candle.base_token_volume, size_precision)
        .context("failed to parse candle base_token_volume")?;

    Ok(Bar::new(
        bar_type, open, high, low, close, volume, ts_event, ts_init,
    ))
}

/// Validates that a ticker has the correct format (BASE-QUOTE).
///
/// # Errors
///
/// Returns an error if the ticker is not in the format "BASE-QUOTE".
pub fn validate_ticker_format(ticker: &str) -> anyhow::Result<()> {
    let parts: Vec<&str> = ticker.split('-').collect();
    if parts.len() != 2 {
        anyhow::bail!("Invalid ticker format '{ticker}', expected 'BASE-QUOTE' (e.g., 'BTC-USD')");
    }

    if parts[0].is_empty() || parts[1].is_empty() {
        anyhow::bail!("Invalid ticker format '{ticker}', base and quote cannot be empty");
    }
    Ok(())
}

/// Parses base and quote currency codes from a ticker.
///
/// # Errors
///
/// Returns an error if the ticker format is invalid.
pub fn parse_ticker_currencies(ticker: &str) -> anyhow::Result<(&str, &str)> {
    validate_ticker_format(ticker)?;
    let parts: Vec<&str> = ticker.split('-').collect();
    Ok((parts[0], parts[1]))
}

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Format the ticker as `BASE-QUOTE`, e.g. `BTC-USD`
  2. Convert exchange-native symbol formats to hyphen-separated form before calling dYdX APIs
  3. Verify the exact ticker with `instruments()` or the dYdX markets endpoint

Example fix

// before
parse_ticker_currencies("BTCUSD")?;
// after
parse_ticker_currencies("BTC-USD")?;
Defensive patterns

Strategy: validation

Validate before calling

fn is_valid_ticker(t: &str) -> bool {
    let parts: Vec<&str> = t.split('-').collect();
    parts.len() == 2 && !parts[0].is_empty() && !parts[1].is_empty()
}

Prevention

When it happens

Trigger: Calling `parse_ticker_currencies` (or any code path that validates tickers) with strings like `"BTCUSD"`, `"BTC/USD"`, `"BTC-USD-PERP"`, or an empty string.

Common situations: Using Binance-style (`BTCUSDT`) or slash-separated symbols; passing an internal instrument ID instead of the venue ticker; config symbols copied from another exchange adapter.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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