rust_okx/api/market/
requests.rs1use serde::Serialize;
2
3use crate::model::InstType;
4
5#[derive(Debug, Clone, Serialize)]
8pub struct InstIdRequest<'a> {
9 #[serde(rename = "instId")]
11 pub inst_id: &'a str,
12}
13
14#[derive(Debug, Clone, Serialize)]
17pub struct TickersRequest<'a> {
18 #[serde(rename = "instType")]
20 pub inst_type: &'a InstType,
21 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
23 pub inst_family: Option<&'a str>,
24}
25
26#[derive(Debug, Clone, Default, Serialize)]
28pub struct IndexTickersRequest<'a> {
29 #[serde(rename = "quoteCcy", skip_serializing_if = "Option::is_none")]
31 pub quote_ccy: Option<&'a str>,
32 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
34 pub inst_id: Option<&'a str>,
35}
36
37#[derive(Debug, Clone, Serialize)]
39pub struct OrderBookRequest<'a> {
40 #[serde(rename = "instId")]
42 pub inst_id: &'a str,
43 #[serde(skip_serializing_if = "Option::is_none")]
45 pub sz: Option<u32>,
46}
47
48#[derive(Debug, Clone, Serialize)]
50pub struct CandlesRequest<'a> {
51 #[serde(rename = "instId")]
53 pub inst_id: &'a str,
54 #[serde(skip_serializing_if = "Option::is_none")]
56 pub bar: Option<&'a str>,
57 #[serde(skip_serializing_if = "Option::is_none")]
59 pub limit: Option<u32>,
60}
61
62#[derive(Debug, Clone, Serialize)]
64pub struct TradesRequest<'a> {
65 #[serde(rename = "instId")]
67 pub inst_id: &'a str,
68 #[serde(skip_serializing_if = "Option::is_none")]
70 pub limit: Option<u32>,
71}
72
73#[derive(Debug, Clone, Serialize)]
75pub struct InstFamilyRequest<'a> {
76 #[serde(rename = "instFamily")]
78 pub inst_family: &'a str,
79}
80
81#[derive(Debug, Clone, Serialize)]
83pub struct IndexRequest<'a> {
84 pub index: &'a str,
86}
87
88#[derive(Debug, Clone, Serialize)]
90pub struct CandlesticksRequest {
91 #[serde(rename = "instId")]
92 inst_id: String,
93 #[serde(skip_serializing_if = "Option::is_none")]
94 after: Option<String>,
95 #[serde(skip_serializing_if = "Option::is_none")]
96 before: Option<String>,
97 #[serde(skip_serializing_if = "Option::is_none")]
98 bar: Option<String>,
99 #[serde(skip_serializing_if = "Option::is_none")]
100 limit: Option<u32>,
101}
102
103impl CandlesticksRequest {
104 pub fn new(inst_id: impl Into<String>) -> Self {
106 Self {
107 inst_id: inst_id.into(),
108 after: None,
109 before: None,
110 bar: None,
111 limit: None,
112 }
113 }
114
115 pub fn after(mut self, after: impl Into<String>) -> Self {
117 self.after = Some(after.into());
118 self
119 }
120
121 pub fn before(mut self, before: impl Into<String>) -> Self {
123 self.before = Some(before.into());
124 self
125 }
126
127 pub fn bar(mut self, bar: impl Into<String>) -> Self {
129 self.bar = Some(bar.into());
130 self
131 }
132
133 pub fn limit(mut self, limit: u32) -> Self {
135 self.limit = Some(limit);
136 self
137 }
138}
139
140#[derive(Debug, Clone, Serialize)]
142pub struct HistoryTradesRequest {
143 #[serde(rename = "instId")]
144 inst_id: String,
145 #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
146 trade_type: Option<String>,
147 #[serde(skip_serializing_if = "Option::is_none")]
148 after: Option<String>,
149 #[serde(skip_serializing_if = "Option::is_none")]
150 before: Option<String>,
151 #[serde(skip_serializing_if = "Option::is_none")]
152 limit: Option<u32>,
153}
154
155impl HistoryTradesRequest {
156 pub fn new(inst_id: impl Into<String>) -> Self {
158 Self {
159 inst_id: inst_id.into(),
160 trade_type: None,
161 after: None,
162 before: None,
163 limit: None,
164 }
165 }
166
167 pub fn trade_type(mut self, trade_type: impl Into<String>) -> Self {
169 self.trade_type = Some(trade_type.into());
170 self
171 }
172
173 pub fn after(mut self, after: impl Into<String>) -> Self {
175 self.after = Some(after.into());
176 self
177 }
178
179 pub fn before(mut self, before: impl Into<String>) -> Self {
181 self.before = Some(before.into());
182 self
183 }
184
185 pub fn limit(mut self, limit: u32) -> Self {
187 self.limit = Some(limit);
188 self
189 }
190}