1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#[derive(thiserror::Error, Debug, Clone, Copy, Serialize, Deserialize)]
/// Defines the possible order errors that can occur when submitting a new order
pub enum OrderError {
    /// Maximum number of active orders reached
    #[error("Maximum number of active orders reached")]
    MaxActiveOrders,

    /// Invalid limit price of order
    #[error("Invalid limit price of order")]
    InvalidLimitPrice,

    /// Invalid trigger price for order
    #[error("Invalid trigger price for order. e.g.: sell stop market order trigger price > ask")]
    InvalidTriggerPrice,

    /// Invalid order size
    #[error("invalid order size")]
    InvalidOrderSize,

    /// The account does not have enought available balance to submit the order
    #[error("The account does not have enough available balance to submit the order")]
    NotEnoughAvailableBalance,
}

/// Describes possible Errors that may occur when calling methods in this crate
#[derive(thiserror::Error, Debug)]
pub enum Error {
    /// Config::new was provided an invalid leverage value
    #[error("Wrong leverage provided")]
    ConfigWrongLeverage,

    /// Config::new was provided an invalid starting balance
    #[error("Wrong starting balance provided")]
    ConfigWrongStartingBalance,

    /// When data could not be parsed
    #[error("could not parse")]
    ParseError,

    /// when cancelling an order but no matching user order id is found
    #[error("user order id not found")]
    UserOrderIdNotFound,

    /// When the internal order id is not found while cancelling order
    #[error("internal order id not found")]
    OrderIdNotFound,
}

/// This is defined as a convenience.
pub type Result<T> = std::result::Result<T, Error>;