nautilus_model/orderbook/
error.rs1use nautilus_core::UnixNanos;
19
20use super::ladder::BookPrice;
21use crate::{
22 enums::{BookType, OrderSide},
23 identifiers::{ClientOrderId, InstrumentId},
24};
25
26#[derive(thiserror::Error, Debug, PartialEq)]
27pub enum InvalidBookOperation {
28 #[error("Invalid book operation: cannot pre-process order for {0} book")]
29 PreProcessOrder(BookType),
30 #[error("Invalid book operation: cannot add order for {0} book")]
31 Add(BookType),
32 #[error("Invalid book operation: cannot update with tick for {0} book")]
33 Update(BookType),
34}
35
36#[derive(thiserror::Error, Debug, PartialEq)]
37pub enum BookIntegrityError {
38 #[error("Integrity error: order not found: order_id={0}, sequence={1}, ts_event={2}")]
39 OrderNotFound(u64, u64, UnixNanos),
40 #[error("Integrity error: invalid `NoOrderSide` in book")]
41 NoOrderSide,
42 #[error("Integrity error: order_id={0} not found in book for side resolution")]
43 OrderNotFoundForSideResolution(u64),
44 #[error("Integrity error: order_id={0} found on both book sides for side resolution")]
45 AmbiguousOrderSide(u64),
46 #[error("Integrity error: orders in cross [{0} {1}]")]
47 OrdersCrossed(BookPrice, BookPrice),
48 #[error("Integrity error: number of {0} orders at level > 1 for L2_MBP book, was {1}")]
49 TooManyOrders(OrderSide, usize),
50 #[error("Integrity error: number of {0} levels > 1 for L1_MBP book, was {1}")]
51 TooManyLevels(OrderSide, usize),
52 #[error("Integrity error: instrument ID mismatch: book={0}, delta={1}")]
53 InstrumentMismatch(InstrumentId, InstrumentId),
54}
55
56#[derive(thiserror::Error, Debug, PartialEq)]
57pub enum BookViewError {
58 #[error("Instrument ID mismatch: book={0}, own_book={1}")]
59 InstrumentMismatch(InstrumentId, InstrumentId),
60
61 #[error("Opposite own book must have different instrument ID: book={0}, opposite={1}")]
62 OppositeInstrumentMatch(InstrumentId, InstrumentId),
63}
64
65#[derive(thiserror::Error, Debug, PartialEq)]
66pub enum OwnBookError {
67 #[error("Own book order not found in cache: client_order_id={client_order_id}")]
68 OrderNotFoundInCache { client_order_id: ClientOrderId },
69 #[error("Own book cached level missing: client_order_id={client_order_id}, price={price:?}")]
70 CachedLevelMissing {
71 client_order_id: ClientOrderId,
72 price: BookPrice,
73 },
74 #[error(
75 "Own book order not found at level: client_order_id={client_order_id}, price={price:?}"
76 )]
77 OrderNotFoundAtLevel {
78 client_order_id: ClientOrderId,
79 price: BookPrice,
80 },
81}