{"record":{"id":"58deee159048f231","repo":"nautechsystems/nautilus_trader","slug":"error-no-bid-orders-for-best-bid-price","errorCode":null,"errorMessage":"Error: No bid orders for best bid price","messagePattern":"Error: No bid orders for best bid price","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/model/src/ffi/orderbook/book.rs","lineNumber":261,"sourceCode":"#[unsafe(no_mangle)]\npub extern \"C\" fn orderbook_has_bid(book: &mut OrderBook) -> u8 {\n    u8::from(book.has_bid())\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn orderbook_has_ask(book: &mut OrderBook) -> u8 {\n    u8::from(book.has_ask())\n}\n\n/// # Panics\n///\n/// Panics if there are no bid orders for best bid price.\n#[unsafe(no_mangle)]\n#[cfg_attr(feature = \"high-precision\", allow(improper_ctypes_definitions))]\npub extern \"C\" fn orderbook_best_bid_price(book: &mut OrderBook) -> Price {\n    abort_on_panic(|| {\n        book.best_bid_price()\n            .expect(\"Error: No bid orders for best bid price\")\n    })\n}\n\n/// # Panics\n///\n/// Panics if there are no ask orders for best ask price.\n#[unsafe(no_mangle)]\n#[cfg_attr(feature = \"high-precision\", allow(improper_ctypes_definitions))]\npub extern \"C\" fn orderbook_best_ask_price(book: &mut OrderBook) -> Price {\n    abort_on_panic(|| {\n        book.best_ask_price()\n            .expect(\"Error: No ask orders for best ask price\")\n    })\n}\n\n/// # Panics\n///\n/// Panics if there are no bid orders for best bid size.","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/orderbook/book.rs#L243-L279","documentation":"This Rust panic occurs in the FFI wrapper `orderbook_best_bid_price` when `OrderBook::best_bid_price()` returns None, i.e. the book's bid side contains no orders so there is no best bid price to return. Because the wrapper runs inside `abort_on_panic`, the panic aborts the whole process rather than returning an error to the FFI caller (e.g. Python).","triggerScenarios":"Calling the FFI function `orderbook_best_bid_price(book)` on an OrderBook whose bid side is empty: no quotes/trades/depth updates have populated bids, all bids were deleted, or the book was just created/cleared.","commonSituations":"Querying a book before the first market-data snapshot arrives; a depth feed that only sent ask-side updates; book_l1/book_l3 data cleared by a `clear` call; instrument-specific books for symbols with no bids (illiquid markets).","solutions":["Check the book has bids before calling: `book.has_orders()` and `book.best_bid_price()` / `book.get_price(Side.BUY)` availability (or check `book.bids()` is non-empty) in the caller.","Ensure the book is initialized with an initial snapshot (e.g. `OrderBookDeltas` or quote/trade data) before querying best prices.","Handle empty-book cases at the strategy level by treating best bid as None and skipping the calculation.","Verify you are querying the correct instrument_id's book and that the data feed is connected and publishing bid-side data."],"exampleFix":"// before (Python FFI caller)\nbest_bid = orderbook_best_bid_price(book)\n// after\nif book_update_count > 0 and has_bid_orders(book):\n    best_bid = orderbook_best_bid_price(book)\nelse:\n    best_bid = None","handlingStrategy":"validation","validationCode":"def can_get_best_bid(book) -> bool:\n    return book.has_orders() and book.bids_len() > 0  # or check best bid price availability","typeGuard":"def has_bid_side(book) -> bool:\n    try:\n        return len(book.bids()) > 0\n    except Exception:\n        return False","tryCatchPattern":null,"preventionTips":["Never call best-bid getters before the first book update arrives","Track a book-ready flag set after the initial snapshot is applied","Treat empty books as an expected state and query optional accessors instead of FFI panicking ones","Remember FFI panics abort the process — they cannot be caught as exceptions"],"tags":["rust","ffi","orderbook","panic","process-abort"],"backgroundTag":"empty-result-set","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}