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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use exc_core::error::ExchangeError;
use thiserror::Error;
use crate::{
key::SignError,
websocket::types::{
messages::{request::WsRequest, Args},
response::StatusKind,
},
};
#[derive(Debug, Error)]
pub enum OkxError {
#[error("stream is dropped")]
StreamDropped,
#[error("weboscket: {0}")]
Websocket(#[from] tokio_tungstenite::tungstenite::Error),
#[error("remote closed")]
RemoteClosed,
#[error("connection error: {0}")]
Connection(Box<dyn std::error::Error + Send + Sync>),
#[error("websocket disconnected")]
WebsocketDisconnected,
#[error("ping error: {0}")]
Ping(anyhow::Error),
#[error("ping timeout")]
PingTimeout,
#[error("json: {0}")]
Json(#[from] serde_json::Error),
#[error("request sender dropped")]
RequestSenderDropped,
#[error("dispatch error: req={0:?}")]
Dispatch(WsRequest),
#[error("responser error: {0}")]
Callback(#[from] tokio::sync::oneshot::error::RecvError),
#[error("already subscribed or unsubscribping {0:?}")]
SubscribedOrUnsubscribing(Args),
#[error("subscribing or unsubscribing {0:?}")]
SubscribingOrUnsubscribing(Args),
#[error("websocket closed")]
WebsocketClosed,
#[error("api error: {0}")]
Api(StatusKind),
#[error("protocol: {0}")]
Protocol(anyhow::Error),
#[error(transparent)]
Layer(Box<dyn std::error::Error + Send + Sync>),
#[error(transparent)]
Buffer(Box<dyn std::error::Error + Send + Sync>),
#[error("unpexpected data type: {0}")]
UnexpectedDataType(anyhow::Error),
#[error("okx key sign error: {0}")]
SignError(#[from] SignError),
#[error("login error: {0}")]
LoginError(anyhow::Error),
}
impl From<OkxError> for ExchangeError {
fn from(err: OkxError) -> Self {
Self::Other(err.into())
}
}