{"record":{"id":"e609141ad797a598","repo":"nautechsystems/nautilus_trader","slug":"cannot-extract-size-from-quote-with-price-type-pr","errorCode":null,"errorMessage":"Cannot extract size from quote with price type {price_type}","messagePattern":"Cannot extract size from quote with price type (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/data/quote.rs","lineNumber":211,"sourceCode":"    ///\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);\n                Quantity::from_raw(\n                    mid_raw,\n                    cmp::min(self.bid_size.precision + 1, FIXED_PRECISION),\n                )\n            }\n            _ => anyhow::bail!(\"Cannot extract size from quote with price type {price_type}\"),\n        };\n        Ok(size)\n    }\n}\n\nimpl Display for QuoteTick {\n    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n        write!(\n            f,\n            \"{},{},{},{},{},{}\",\n            self.instrument_id,\n            self.bid_price,\n            self.ask_price,\n            self.bid_size,\n            self.ask_size,\n            self.ts_event,\n        )\n    }","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/data/quote.rs#L193-L229","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use only PriceType::Bid, PriceType::Ask, or PriceType::Mid with QuoteTick::extract_size.","Obtain LAST/trade sizes from TradeTick instead of QuoteTick.","Guard the configured PriceType before wiring it into the quote handler; fail fast at startup with a clear message."],"exampleFix":"// before\nlet size = quote.extract_size(PriceType::LAST)?;\n// after\nanyhow::ensure!(\n    matches!(price_type, PriceType::Bid | PriceType::Ask | PriceType::Mid),\n    \"quote sizes require Bid/Ask/Mid, got {price_type:?}\"\n);\nlet size = quote.extract_size(price_type)?;","handlingStrategy":"validation","validationCode":"// Rust\nfn quote_size_supports(pt: PriceType) -> bool {\n    matches!(pt, PriceType::Bid | PriceType::Ask | PriceType::Mid)\n}\n# Python\n# assert price_type in (PriceType.BID, PriceType.ASK, PriceType.MID)","typeGuard":"// Rust\nfn quote_size_price_type(pt: PriceType) -> Option<PriceType> {\n    matches!(pt, PriceType::Bid | PriceType::Ask | PriceType::Mid).then_some(pt)\n}","tryCatchPattern":"// Python\ntry:\n    size = quote.extract_size(price_type)\nexcept ValueError as e:\n    if \"Cannot extract size\" in str(e):\n        logger.warning(f\"{price_type} size not available on quotes\")\n    else:\n        raise","preventionTips":["Only request Bid/Ask/Mid sizes from quote ticks.","Route LAST-size requests to trade tick handlers.","Add an assertion near the handler entry point that the PriceType is quote-compatible."],"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"}