nautilus_model/orderbook/
error.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Errors associated with order book operations and integrity.
17
18use nautilus_core::UnixNanos;
19
20use super::ladder::BookPrice;
21use crate::enums::{BookType, OrderSide};
22
23#[derive(thiserror::Error, Debug, PartialEq)]
24pub enum InvalidBookOperation {
25    #[error("Invalid book operation: cannot pre-process order for {0} book")]
26    PreProcessOrder(BookType),
27    #[error("Invalid book operation: cannot add order for {0} book")]
28    Add(BookType),
29    #[error("Invalid book operation: cannot update with tick for {0} book")]
30    Update(BookType),
31}
32
33#[derive(thiserror::Error, Debug, PartialEq)]
34pub enum BookIntegrityError {
35    #[error("Integrity error: order not found: order_id={0}, sequence={1}, ts_event={2}")]
36    OrderNotFound(u64, u64, UnixNanos),
37    #[error("Integrity error: invalid `NoOrderSide` in book")]
38    NoOrderSide,
39    #[error("Integrity error: orders in cross [{0} {1}]")]
40    OrdersCrossed(BookPrice, BookPrice),
41    #[error("Integrity error: number of {0} orders at level > 1 for L2_MBP book, was {1}")]
42    TooManyOrders(OrderSide, usize),
43    #[error("Integrity error: number of {0} levels > 1 for L1_MBP book, was {1}")]
44    TooManyLevels(OrderSide, usize),
45}