Skip to main content

clob_sync/
error.rs

1use crate::order::{Price, Symbol};
2use crate::order_book_side::BookSide;
3use fastnum::D128 as Dec;
4use fastnum::decimal::ParseError;
5
6/// Errors that can occur during order book operations.
7#[derive(thiserror::Error, Debug)]
8pub enum Error {
9    /// The order symbol does not match the order book symbol.
10    #[error("expected: {expected}, received: {received}")]
11    InvalidSymbol { expected: Symbol, received: Symbol },
12
13    /// A limit buy order's price is not better than (i.e., not higher than) the best ask.
14    #[error(
15        "Limit buy order price {limit_price} must be better than top of sell price {sell_price}"
16    )]
17    LimitBuyOrderWorstThanTopOfSells { limit_price: Dec, sell_price: Dec },
18
19    /// A limit sell order's price is not better than (i.e., not lower than) the best bid.
20    #[error(
21        "Limit sell order price {limit_price} must be better than top of buy price {buy_price}"
22    )]
23    LimitSellOrderWorstThanTopOfBuys { limit_price: Dec, buy_price: Dec },
24
25    /// A limit order's price does not improve upon the top order on the book.
26    #[error(
27        "Limit price {limit_price} not better than top order price {top_order_price}"
28    )]
29    LimitPriceNotBetterThanTop {
30        book_side: BookSide,
31        limit_price: Price,
32        top_order_price: Price,
33    },
34
35    /// Failed to parse a decimal string (price or quantity).
36    #[error("cannot parse decimal: {0}")]
37    DecimalParseError(#[from] ParseError),
38}