nautechsystems/nautilus_trader · error

Cannot extract price from quote with price type {price_type}

Error message

Cannot extract price from quote with price type {price_type}

What it means

QuoteTick::extract_price returns the tick's price according to a PriceType. Bid, ask, and mid are supported (mid uses the midpoint of bid/ask raw values); any other PriceType value falls through the match and bails, since a quote tick has no price for that type.

Source

Thrown at crates/model/src/data/quote.rs:187

    ///
    /// # Errors
    ///
    /// Returns an error if `price_type` is not `Bid`, `Ask`, or `Mid` (a quote has no `Last` price).
    pub fn extract_price(&self, price_type: PriceType) -> anyhow::Result<Price> {
        let price = match price_type {
            PriceType::Bid => self.bid_price,
            PriceType::Ask => self.ask_price,
            PriceType::Mid => {
                // Calculate mid avoiding overflow
                let a = self.bid_price.raw;
                let b = self.ask_price.raw;
                let mid_raw = a.midpoint(b);
                Price::from_raw(
                    mid_raw,
                    cmp::min(self.bid_price.precision + 1, FIXED_PRECISION),
                )
            }
            _ => anyhow::bail!("Cannot extract price from quote with price type {price_type}"),
        };
        Ok(price)
    }

    /// Returns the [`Quantity`] for this quote depending on the given `price_type`.
    ///
    /// # Errors
    ///
    /// Returns an error if `price_type` is not `Bid`, `Ask`, or `Mid` (a quote has no `Last` size).
    pub fn extract_size(&self, price_type: PriceType) -> anyhow::Result<Quantity> {
        let size = match price_type {
            PriceType::Bid => self.bid_size,
            PriceType::Ask => self.ask_size,
            PriceType::Mid => {
                // Calculate mid avoiding overflow
                let a = self.bid_size.raw;
                let b = self.ask_size.raw;
                let mid_raw = a.midpoint(b);

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Use PriceType::Bid, PriceType::Ask, or PriceType::Mid when working with QuoteTick data.
  2. For LAST prices, source from trade ticks (TradeTick::extract_price) instead of quotes.
  3. If the PriceType comes from config, validate/whitelist it to the quote-supported set before the data handler runs.

Example fix

// before
let price = quote.extract_price(PriceType::LAST)?;
// after
let price = match price_type {
    PriceType::Bid | PriceType::Ask | PriceType::Mid => quote.extract_price(price_type)?,
    _ => return Ok(trade_tick.extract_price(price_type)?), // LAST etc. from trades
};
Defensive patterns

Strategy: validation

Validate before calling

// Rust
use nautilus_model::enums::PriceType;
fn quote_supports(price_type: PriceType) -> bool {
    matches!(price_type, PriceType::Bid | PriceType::Ask | PriceType::Mid)
}
# Python
# def quote_supports(pt): return pt in (PriceType.BID, PriceType.ASK, PriceType.MID)

Type guard

// Rust
fn as_quote_price_type(pt: PriceType) -> Option<PriceType> {
    matches!(pt, PriceType::Bid | PriceType::Ask | PriceType::Mid).then_some(pt)
}

Try / catch

// Python
try:
    price = quote.extract_price(price_type)
except ValueError as e:
    if "Cannot extract price" in str(e):
        logger.warning(f"{price_type} unavailable on quotes; using trade tick fallback")
    else:
        raise

Prevention

When it happens

Trigger: Calling extract_price (Rust) or py_extract_price (Python binding) with a PriceType such as LAST, or any variant outside Bid/Ask/Mid; strategy handlers (handle_quote) requesting a price type a quote cannot provide.

Common situations: Reusing a strategy written for trade ticks (which have LAST prices) against quote data; a config-driven PriceType resolved to an unsupported variant; enum extended with new variants not yet handled by the match.

Related errors


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