nautechsystems/nautilus_trader · error · anyhow::Error

Cannot resolve raw_symbol for instrument_id {raw_instrument_

Error message

Cannot resolve raw_symbol for instrument_id {raw_instrument_id}

What it means

When translating a Databento numeric instrument_id to a Nautilus InstrumentId using an exchange string, the point-in-time symbol map has no raw symbol registered for that numeric ID. Without a raw symbol the adapter cannot construct a valid instrument identifier.

Source

Thrown at crates/adapters/databento/src/live.rs:1076

        });

    if let Some(price_precision) = price_precision {
        subscription_price_precision_map.insert(msg.hd.instrument_id, price_precision);
    }

    Ok(())
}

/// Updates the instrument ID map using exchange information from the symbol map.
fn update_instrument_id_map_with_exchange(
    symbol_map: &PitSymbolMap,
    symbol_venue_map: &AtomicMap<Symbol, Venue>,
    instrument_id_map: &mut AHashMap<u32, InstrumentId>,
    raw_instrument_id: u32,
    exchange: &str,
) -> anyhow::Result<InstrumentId> {
    let raw_symbol = symbol_map.get(raw_instrument_id).ok_or_else(|| {
        anyhow::anyhow!("Cannot resolve raw_symbol for instrument_id {raw_instrument_id}")
    })?;
    let symbol = Symbol::from(raw_symbol.as_str());
    let venue = Venue::from_code(exchange)
        .map_err(|e| anyhow::anyhow!("Invalid venue code '{exchange}': {e}"))?;
    let instrument_id = InstrumentId::new(symbol, venue);
    symbol_venue_map.rcu(|m| {
        m.entry(symbol).or_insert(venue);
    });
    instrument_id_map.insert(raw_instrument_id, instrument_id);
    Ok(instrument_id)
}

fn update_instrument_id_map(
    record: &dbn::RecordRef,
    symbol_map: &PitSymbolMap,
    publisher_venue_map: &IndexMap<PublisherId, Venue>,
    symbol_venue_map: &AtomicMap<Symbol, Venue>,
    instrument_id_map: &mut AHashMap<u32, InstrumentId>,

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Load instrument definitions first (load_instruments / definition schema) so the symbol map is populated before other record types
  2. Subscribe to the symbol mapping schema so PitSymbolMap gets filled for the instruments in the stream
  3. Check for records arriving out of order; add retry/requeue logic so the record is reprocessed once the symbol map is populated
  4. Verify the instrument_id actually belongs to your subscription universe; filter unexpected IDs before processing

Example fix

// before: hard failure on first unseen instrument_id
let raw_symbol = symbol_map.get(raw_instrument_id).ok_or_else(|| {
    anyhow::anyhow!("Cannot resolve raw_symbol for instrument_id {raw_instrument_id}")
})?;
// after: skip and warn until the mapping arrives
let raw_symbol = match symbol_map.get(raw_instrument_id) {
    Some(s) => s,
    None => {
        log::warn!("raw_symbol not yet mapped for {raw_instrument_id}; skipping record");
        return Ok(instrument_id_placeholder);
    }
};
Defensive patterns

Strategy: validation

Validate before calling

// before streaming, ensure the symbol map knows your instruments
let mapped = symbol_map.get(raw_instrument_id);
assert!(mapped.is_some(), "call load_instruments / subscribe symbol mapping first");

Try / catch

match update_instrument_id_map_with_exchange(...) {
    Ok(id) => id,
    Err(e) if e.to_string().contains("Cannot resolve raw_symbol") => {
        log::warn!("mapping not ready: {e}"); /* requeue record */
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: `update_instrument_id_map_with_exchange` is invoked from run_session with a raw_instrument_id that was never inserted into the PitSymbolMap — e.g. records arrive before the corresponding symbol-mapping/definition data populated the map.

Common situations: Subscribing to schemas that emit records for instruments not covered by loaded definitions, starting the stream before symbol map initialization completes, or a publisher whose symbol mappings arrive late.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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