nautechsystems/nautilus_trader · error

Cannot extract size from quote with price type {price_type}

Error message

Cannot extract size from quote with price type {price_type}

What it means

QuoteTick::extract_size returns the tick's quantity for a given PriceType. Bid, ask, and mid sizes are supported (mid averages bid/ask raw sizes); any other PriceType falls through the match and bails because a quote has no size for it.

Source

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

    ///
    /// # 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);
                Quantity::from_raw(
                    mid_raw,
                    cmp::min(self.bid_size.precision + 1, FIXED_PRECISION),
                )
            }
            _ => anyhow::bail!("Cannot extract size from quote with price type {price_type}"),
        };
        Ok(size)
    }
}

impl Display for QuoteTick {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{},{},{},{},{},{}",
            self.instrument_id,
            self.bid_price,
            self.ask_price,
            self.bid_size,
            self.ask_size,
            self.ts_event,
        )
    }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Use only PriceType::Bid, PriceType::Ask, or PriceType::Mid with QuoteTick::extract_size.
  2. Obtain LAST/trade sizes from TradeTick instead of QuoteTick.
  3. Guard the configured PriceType before wiring it into the quote handler; fail fast at startup with a clear message.

Example fix

// before
let size = quote.extract_size(PriceType::LAST)?;
// after
anyhow::ensure!(
    matches!(price_type, PriceType::Bid | PriceType::Ask | PriceType::Mid),
    "quote sizes require Bid/Ask/Mid, got {price_type:?}"
);
let size = quote.extract_size(price_type)?;
Defensive patterns

Strategy: validation

Validate before calling

// Rust
fn quote_size_supports(pt: PriceType) -> bool {
    matches!(pt, PriceType::Bid | PriceType::Ask | PriceType::Mid)
}
# Python
# assert price_type in (PriceType.BID, PriceType.ASK, PriceType.MID)

Type guard

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

Try / catch

// Python
try:
    size = quote.extract_size(price_type)
except ValueError as e:
    if "Cannot extract size" in str(e):
        logger.warning(f"{price_type} size not available on quotes")
    else:
        raise

Prevention

When it happens

Trigger: Calling extract_size (Rust) or py_extract_size (Python binding) on a QuoteTick with a PriceType other than Bid/Ask/Mid, e.g. LAST; handle_quote dispatching an unsupported size type.

Common situations: Strategies built around trade-tick sizes applied to quote data; configuration supplying a PriceType valid only for bars or trades; new PriceType variants added without updating quote extraction.

Related errors


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