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// -------------------------------------------------------------------------------------------------
1516//! Errors associated with order book operations and integrity.
1718use nautilus_core::UnixNanos;
1920use super::ladder::BookPrice;
21use crate::enums::{BookType, OrderSide};
2223#[derive(thiserror::Error, Debug, PartialEq)]
24pub enum InvalidBookOperation {
25#[error("Invalid book operation: cannot pre-process order for {0} book")]
26PreProcessOrder(BookType),
27#[error("Invalid book operation: cannot add order for {0} book")]
28Add(BookType),
29#[error("Invalid book operation: cannot update with tick for {0} book")]
30Update(BookType),
31}
3233#[derive(thiserror::Error, Debug, PartialEq)]
34pub enum BookIntegrityError {
35#[error("Integrity error: order not found: order_id={0}, sequence={1}, ts_event={2}")]
36OrderNotFound(u64, u64, UnixNanos),
37#[error("Integrity error: invalid `NoOrderSide` in book")]
38NoOrderSide,
39#[error("Integrity error: orders in cross [{0} {1}]")]
40OrdersCrossed(BookPrice, BookPrice),
41#[error("Integrity error: number of {0} orders at level > 1 for L2_MBP book, was {1}")]
42TooManyOrders(OrderSide, usize),
43#[error("Integrity error: number of {0} levels > 1 for L1_MBP book, was {1}")]
44TooManyLevels(OrderSide, usize),
45}