Skip to main content

rs_clob_client/
errors.rs

1use thiserror::Error;
2
3/// Errors that can occur when using the CLOB client
4#[derive(Error, Debug)]
5pub enum ClobError {
6    /// HTTP request error
7    #[error("HTTP request failed: {0}")]
8    HttpError(#[from] reqwest::Error),
9
10    /// JSON serialization/deserialization error
11    #[error("JSON error: {0}")]
12    JsonError(#[from] serde_json::Error),
13
14    /// Authentication error - L1 (wallet signature required)
15    #[error("Signer is needed to interact with this endpoint")]
16    L1AuthUnavailable,
17
18    /// Authentication error - L2 (API credentials required)
19    #[error("API Credentials are needed to interact with this endpoint")]
20    L2AuthNotAvailable,
21
22    /// Builder authentication error
23    #[error("Builder API Credentials needed to interact with this endpoint")]
24    BuilderAuthNotAvailable,
25
26    /// Builder authentication failed
27    #[error("Builder key auth failed")]
28    BuilderAuthFailed,
29
30    /// Invalid price
31    #[error("Invalid price ({price}), min: {min} - max: {max}")]
32    InvalidPrice { price: f64, min: f64, max: f64 },
33
34    /// Invalid tick size
35    #[error("Invalid tick size ({tick_size}), minimum for the market is {min_tick_size}")]
36    InvalidTickSize {
37        tick_size: String,
38        min_tick_size: String,
39    },
40
41    /// Invalid fee rate
42    #[error("Invalid user provided fee rate: {user_fee_rate}, fee rate for the market must be {market_fee_rate}")]
43    InvalidFeeRate {
44        user_fee_rate: u32,
45        market_fee_rate: u32,
46    },
47
48    /// No orderbook available
49    #[error("No orderbook available")]
50    NoOrderbook,
51
52    /// No match in orderbook
53    #[error("No match found in orderbook")]
54    NoMatch,
55
56    /// Ethereum wallet error
57    #[error("Ethereum wallet error: {0}")]
58    WalletError(String),
59
60    /// EIP-712 signing error
61    #[error("EIP-712 signing error: {0}")]
62    SigningError(String),
63
64    /// Base64 decoding error
65    #[error("Base64 decode error: {0}")]
66    Base64Error(#[from] base64::DecodeError),
67
68    /// Invalid configuration
69    #[error("Invalid configuration: {0}")]
70    ConfigError(String),
71
72    /// API error response
73    #[error("API error: {message}")]
74    ApiError { message: String, status: u16 },
75
76    /// Generic error
77    #[error("{0}")]
78    Other(String),
79}
80
81/// Result type alias for CLOB operations
82pub type ClobResult<T> = Result<T, ClobError>;