{"record":{"id":"5c32cac944e2c440","repo":"nautechsystems/nautilus_trader","slug":"cannot-extract-price-from-quote-with-price-type-p","errorCode":null,"errorMessage":"Cannot extract price from quote with price type {price_type}","messagePattern":"Cannot extract price from quote with price type (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/data/quote.rs","lineNumber":187,"sourceCode":"    ///\n    /// # Errors\n    ///\n    /// Returns an error if `price_type` is not `Bid`, `Ask`, or `Mid` (a quote has no `Last` price).\n    pub fn extract_price(&self, price_type: PriceType) -> anyhow::Result<Price> {\n        let price = match price_type {\n            PriceType::Bid => self.bid_price,\n            PriceType::Ask => self.ask_price,\n            PriceType::Mid => {\n                // Calculate mid avoiding overflow\n                let a = self.bid_price.raw;\n                let b = self.ask_price.raw;\n                let mid_raw = a.midpoint(b);\n                Price::from_raw(\n                    mid_raw,\n                    cmp::min(self.bid_price.precision + 1, FIXED_PRECISION),\n                )\n            }\n            _ => anyhow::bail!(\"Cannot extract price from quote with price type {price_type}\"),\n        };\n        Ok(price)\n    }\n\n    /// Returns the [`Quantity`] for this quote depending on the given `price_type`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if `price_type` is not `Bid`, `Ask`, or `Mid` (a quote has no `Last` size).\n    pub fn extract_size(&self, price_type: PriceType) -> anyhow::Result<Quantity> {\n        let size = match price_type {\n            PriceType::Bid => self.bid_size,\n            PriceType::Ask => self.ask_size,\n            PriceType::Mid => {\n                // Calculate mid avoiding overflow\n                let a = self.bid_size.raw;\n                let b = self.ask_size.raw;\n                let mid_raw = a.midpoint(b);","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/data/quote.rs#L169-L205","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use PriceType::Bid, PriceType::Ask, or PriceType::Mid when working with QuoteTick data.","For LAST prices, source from trade ticks (TradeTick::extract_price) instead of quotes.","If the PriceType comes from config, validate/whitelist it to the quote-supported set before the data handler runs."],"exampleFix":"// before\nlet price = quote.extract_price(PriceType::LAST)?;\n// after\nlet price = match price_type {\n    PriceType::Bid | PriceType::Ask | PriceType::Mid => quote.extract_price(price_type)?,\n    _ => return Ok(trade_tick.extract_price(price_type)?), // LAST etc. from trades\n};","handlingStrategy":"validation","validationCode":"// Rust\nuse nautilus_model::enums::PriceType;\nfn quote_supports(price_type: PriceType) -> bool {\n    matches!(price_type, PriceType::Bid | PriceType::Ask | PriceType::Mid)\n}\n# Python\n# def quote_supports(pt): return pt in (PriceType.BID, PriceType.ASK, PriceType.MID)","typeGuard":"// Rust\nfn as_quote_price_type(pt: PriceType) -> Option<PriceType> {\n    matches!(pt, PriceType::Bid | PriceType::Ask | PriceType::Mid).then_some(pt)\n}","tryCatchPattern":"// Python\ntry:\n    price = quote.extract_price(price_type)\nexcept ValueError as e:\n    if \"Cannot extract price\" in str(e):\n        logger.warning(f\"{price_type} unavailable on quotes; using trade tick fallback\")\n    else:\n        raise","preventionTips":["Match the data type to the PriceType: LAST comes from trades, Bid/Ask/Mid from quotes.","Validate configured PriceTypes at strategy startup.","Centralize price extraction behind a helper that dispatches on tick kind."],"tags":["market-data","enum","quote-tick"],"backgroundTag":"unsupported-enum-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}