Skip to main content

bybit/ws/
error.rs

1/// Errors of the WebSocket driver and its [`Handle`](crate::ws::Handle).
2#[derive(Debug, thiserror::Error)]
3pub enum Error {
4    /// The stream URL is invalid.
5    #[error("invalid URL: {0}")]
6    InvalidUrl(String),
7
8    /// The command queue is full (`try_*` methods of [`Handle`](crate::ws::Handle)).
9    #[error("command queue full - backpressure limit reached")]
10    QueueFull,
11
12    /// The driver task has stopped.
13    #[error("driver has shut down")]
14    DriverGone,
15
16    /// WebSocket protocol or transport error.
17    #[error("websocket error: {0}")]
18    WebSocket(#[from] tokio_tungstenite::tungstenite::Error),
19
20    /// I/O error.
21    #[error("io error: {0}")]
22    Io(#[from] std::io::Error),
23
24    /// [`TradeClient`](crate::ws::TradeClient) needs `api_key` and
25    /// `api_secret` in the [`Config`](crate::ws::Config).
26    #[error("api_key and api_secret are required for the order entry stream")]
27    MissingCredentials,
28
29    /// An order entry request was sent while the stream was not connected
30    /// and authenticated ([`TradeClient`](crate::ws::TradeClient)).
31    #[error("order entry stream is not connected and authenticated")]
32    NotConnected,
33
34    /// No reply to an order entry request within the request timeout. The
35    /// order may or may not have been accepted: check it before retrying.
36    #[error("no reply within the request timeout")]
37    Timeout,
38
39    /// The connection was lost before the reply arrived. The order may or
40    /// may not have been accepted: check it before retrying.
41    #[error("connection lost before the reply arrived")]
42    ConnectionLost,
43
44    /// Bybit rejected the request (see [`ret_code`](crate::ret_code)).
45    #[error("Bybit API error: code: {code}, message: {msg}")]
46    Api {
47        /// Bybit `retCode`.
48        code: i64,
49        /// Bybit `retMsg`.
50        msg: String,
51    },
52
53    /// The reply data could not be parsed.
54    #[error("invalid reply: {0}")]
55    InvalidReply(String),
56}