exc_binance/http/
error.rs

1use exc_core::ExchangeError;
2use thiserror::Error;
3
4/// Rest API Errors.
5#[derive(Debug, Error)]
6pub enum RestError {
7    /// API error message.
8    #[error("api: code={0} msg={0}")]
9    Api(i64, String),
10    /// Http errors.
11    #[error("http: {0}")]
12    Http(#[from] http::Error),
13    /// Errors from hyper.
14    #[error("hyper: {0}")]
15    Hyper(#[from] hyper::Error),
16    /// Json errors.
17    #[error("json: {0}")]
18    Json(#[from] serde_json::Error),
19    /// Urlencoded.
20    #[error("urlencoded: {0}")]
21    Urlencoded(#[from] serde_urlencoded::ser::Error),
22    /// Standard exchange errors.
23    #[error("exchange: {0}")]
24    Exchange(#[from] ExchangeError),
25    /// Invalid header value.
26    #[error("invalid header value: {0}")]
27    InvalidHeaderValue(#[from] http::header::InvalidHeaderValue),
28    /// Unexpected response type.
29    #[error("unexpected response type: {0}")]
30    UnexpectedResponseType(anyhow::Error),
31    /// Unsupported endpoint.
32    #[error("unsuppored endpoint: {0}")]
33    UnsupportedEndpoint(anyhow::Error),
34    /// Need key.
35    #[error("need apikey to sign the params")]
36    NeedApikey,
37    /// Sign error.
38    #[error("sign error: {0}")]
39    SignError(#[from] crate::types::key::SignError),
40    /// Utf-8 error.
41    #[error("utf-8 error: {0}")]
42    Utf8(#[from] std::str::Utf8Error),
43    /// Text response.
44    #[error("text response: {0}")]
45    Text(String),
46    /// Place Zero size.
47    #[error("trying to place an order with zero size")]
48    PlaceZeroSize,
49    /// Parse Symbol Error.
50    #[error("parse symbol error: {0}")]
51    ParseSymbol(#[from] exc_core::ParseSymbolError),
52    /// Failed to build exc symbol.
53    #[error("failed to build exc symbol")]
54    FailedToBuildExcSymbol,
55    /// Missing date for futures.
56    #[error("missing date for futures")]
57    MissingDateForFutures,
58    /// Invalid date for options.
59    #[error("invalid date for options")]
60    InvalidDateForOptions,
61    /// Missing base asset for options.
62    #[error("missing base asset for options")]
63    MissingBaseAssetForOptions,
64    /// Unknown contract type.
65    #[error("unknown contract type: {0:?}")]
66    UnknownContractType(String),
67}
68
69impl RestError {
70    /// Is temp.
71    pub fn is_temporary(&self) -> bool {
72        if let Self::Exchange(err) = self {
73            err.is_temporary()
74        } else {
75            false
76        }
77    }
78}