nautechsystems/nautilus_trader · error · anyhow::Error

Could not resolve `price_precision` for {instrument_id}: pas

Error message

Could not resolve `price_precision` for {instrument_id}: pass `price_precision` explicitly, call `set_price_precision`, or load the instrument definitions first via `load_instruments`

What it means

The Databento loader must know each instrument's price precision to build Nautilus types from raw integer prices. When no explicit `price_precision` argument is given and the symbol has no cached precision (via set_price_precision or load_instruments), resolution fails with this instructive error.

Source

Thrown at crates/adapters/databento/src/loader.rs:218

    /// 2. The cached precision for the instrument's symbol.
    ///
    /// # Errors
    ///
    /// Returns an error when no precision is available.
    fn resolve_price_precision(
        &self,
        instrument_id: &InstrumentId,
        price_precision: Option<u8>,
    ) -> anyhow::Result<u8> {
        if let Some(precision) = price_precision {
            return Ok(precision);
        }

        self.price_precisions
            .get(&instrument_id.symbol)
            .copied()
            .ok_or_else(|| {
                anyhow::anyhow!(
                    "Could not resolve `price_precision` for {instrument_id}: \
                     pass `price_precision` explicitly, call `set_price_precision`, \
                     or load the instrument definitions first via `load_instruments`"
                )
            })
    }

    /// Returns the schema for the given `filepath`.
    ///
    /// # Errors
    ///
    /// Returns an error if the file cannot be decoded or metadata retrieval fails.
    pub fn schema_from_file(&self, filepath: &Path) -> anyhow::Result<Option<String>> {
        let decoder = Decoder::from_zstd_file(filepath)?;
        let metadata = decoder.metadata();
        Ok(metadata.schema.map(|schema| schema.to_string()))
    }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Call `load_instruments` on the definition-schema file for your dataset before decoding data records
  2. Pass `price_precision: Some(n)` explicitly to the decode call for the instrument
  3. Call `loader.set_price_precision(symbol, precision)` for each symbol you will decode
  4. Verify the cached symbol exactly matches the record's symbol (watch for suffixes/case differences)

Example fix

// before
let instrument = loader.decode(msg, None, instrument_id)?; // panics into error: no cache
// after
loader.set_price_precision(instrument_id.symbol, 2);
let instrument = loader.decode(msg, None, instrument_id)?;
// or: loader.load_instruments(&definition_path, ...)?;
Defensive patterns

Strategy: validation

Validate before calling

// before decoding records, ensure precision is resolvable
if loader.get_price_precisions().get(&instrument_id.symbol).is_none() {
    loader.set_price_precision(instrument_id.symbol, expected_precision);
}

Try / catch

match loader.decode(msg, None, instrument_id) {
    Ok(i) => i,
    Err(e) if e.to_string().contains("Could not resolve `price_precision`") => {
        anyhow::bail!("pass price_precision or call load_instruments first: {e}")
    }
    other => other,
}

Prevention

When it happens

Trigger: Calling a DatabentoDataLoader read/decode method for a symbol whose definitions were never loaded via load_instruments, without passing `price_precision` and without a prior `set_price_precision(symbol, ...)` call. Note the cache is keyed by Symbol, not full InstrumentId, so a symbol mismatch (e.g. different suffix) also misses.

Common situations: Decoding a subset schema file without its definition file, symbol key mismatch (raw symbol vs continuous/instrument symbol with suffix), fresh loader instance where a previous instance held the cache.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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