barter_data/exchange/gateio/
message.rs

1use serde::{Deserialize, Serialize};
2
3/// [`Gateio`](super::Gateio) WebSocket message.
4///
5/// ### Raw Payload Examples
6/// #### Subscription Trades Success
7/// See docs: <https://www.gate.io/docs/developers/apiv4/ws/en/#api-overview>
8/// ```json
9/// {
10///     "time": 1606292218,
11///     "time_ms": 1606292218231,
12///     "channel": "spot.trades",
13///     "event": "subscribe",
14///     "result": {
15///         "status": "success"
16///     }
17/// }
18/// ```
19///
20/// #### Subscription Trades Failure
21/// See docs: <https://www.gate.io/docs/developers/apiv4/ws/en/#api-overview>
22/// ```json
23/// {
24///     "time": 1606292218,
25///     "time_ms": 1606292218231,
26///     "channel": "spot.trades",
27///     "event": "subscribe",
28///     "error":{
29///         "code":2,
30///         "message":"unknown currency pair GIBBERISH_USD"
31///     },
32///     "result": null,
33/// }
34/// ```
35///
36/// #### Spot Trade
37/// See docs: <https://www.gate.io/docs/developers/apiv4/ws/en/#public-trades-channel>
38/// ```json
39/// {
40///     "time": 1606292218,
41///     "time_ms": 1606292218231,
42///     "channel": "spot.trades",
43///     "event": "update",
44///     "result": {
45///         "id": 309143071,
46///         "create_time": 1606292218,
47///         "create_time_ms": "1606292218213.4578",
48///         "side": "sell",
49///         "currency_pair": "GT_USDT",
50///         "amount": "16.4700000000",
51///         "price": "0.4705000000"
52///     }
53/// }
54/// ```
55///
56/// See docs: <https://www.gate.io/docs/developers/apiv4/ws/en/#public-trades-channel>
57#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Deserialize, Serialize)]
58pub struct GateioMessage<T> {
59    pub channel: String,
60    pub error: Option<GateioError>,
61    #[serde(rename = "result")]
62    pub data: T,
63}
64
65/// [`Gateio`](super::Gateio) WebSocket error message.
66///
67/// See docs: <https://www.gate.io/docs/developers/apiv4/ws/en/#public-trades-channel>
68#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Deserialize, Serialize)]
69pub struct GateioError {
70    pub code: u8,
71    pub message: String,
72}