rust_okx/ws/model/status.rs
1//! System status channel model (`status`).
2//!
3//! Public channel; no authentication required.
4
5use serde::Deserialize;
6
7use super::ExtraFields;
8use crate::model::NumberString;
9
10/// Public `status` channel row.
11///
12/// OKX docs: <https://www.okx.com/docs-v5/en/#status-websocket-status-channel>
13#[derive(Debug, Clone, Default, Deserialize)]
14#[serde(rename_all = "camelCase")]
15#[non_exhaustive]
16pub struct StatusUpdate {
17 /// Title of the maintenance event.
18 #[serde(default)]
19 pub title: String,
20 /// Current state of the event.
21 ///
22 /// Documented values: `scheduled`, `ongoing`, `pre_open`, `completed`, `canceled`.
23 #[serde(default)]
24 pub state: String,
25 /// Maintenance start time (Unix milliseconds).
26 #[serde(default)]
27 pub begin: NumberString,
28 /// Maintenance end time (Unix milliseconds).
29 ///
30 /// Expected end time before `completed`; actual end time after `completed`.
31 #[serde(default)]
32 pub end: NumberString,
33 /// Pre-open phase start time (Unix milliseconds).
34 ///
35 /// Empty string when the event has no pre-open phase.
36 #[serde(default)]
37 pub pre_open_begin: NumberString,
38 /// URL for more information about the event.
39 ///
40 /// Empty string when not provided.
41 #[serde(default)]
42 pub href: String,
43 /// Affected service type.
44 ///
45 /// Documented values: `0` WebSocket; `5` Trading service; `6` Block trading;
46 /// `7` Trading bot; `8` Trading service (in batches of accounts);
47 /// `9` Trading service (in batches of products); `10` Spread trading;
48 /// `11` Copy trading; `99` Others.
49 #[serde(default)]
50 pub service_type: String,
51 /// System affected by the maintenance.
52 ///
53 /// Documented values: `unified` Trading account.
54 #[serde(default)]
55 pub system: String,
56 /// Rescheduled description.
57 #[serde(default)]
58 pub sche_desc: String,
59 /// Maintenance type.
60 ///
61 /// Documented values: `1` Scheduled maintenance; `2` Unscheduled maintenance;
62 /// `3` System disruption.
63 #[serde(default)]
64 pub maint_type: String,
65 /// Environment: `1` Production Trading; `2` Demo Trading.
66 #[serde(default)]
67 pub env: String,
68 /// Push time due to change event (Unix milliseconds).
69 #[serde(default)]
70 pub ts: NumberString,
71 /// Unrecognized fields retained for forward compatibility.
72 #[serde(flatten, default)]
73 pub extra: ExtraFields,
74}
75
76#[cfg(test)]
77mod tests {
78 use super::*;
79
80 #[test]
81 fn deserializes_docs_push_data_example() {
82 let json = r#"{
83 "begin": "1672823400000",
84 "end": "1672825980000",
85 "href": "",
86 "preOpenBegin": "",
87 "scheDesc": "",
88 "serviceType": "0",
89 "state": "completed",
90 "system": "unified",
91 "maintType": "1",
92 "env": "1",
93 "title": "Trading account WebSocket system upgrade",
94 "ts": "1672826038470"
95 }"#;
96
97 let row: StatusUpdate = serde_json::from_str(json).expect("should deserialize");
98 assert_eq!(row.title, "Trading account WebSocket system upgrade");
99 assert_eq!(row.state, "completed");
100 assert_eq!(row.begin.as_str(), "1672823400000");
101 assert_eq!(row.end.as_str(), "1672825980000");
102 assert!(row.pre_open_begin.is_empty());
103 assert_eq!(row.service_type, "0");
104 assert_eq!(row.system, "unified");
105 assert_eq!(row.maint_type, "1");
106 assert_eq!(row.env, "1");
107 assert_eq!(row.ts.as_str(), "1672826038470");
108 assert!(row.extra.is_empty());
109 }
110}