1use std::borrow::Cow;
2
3use serde::Serialize;
4
5use crate::model::InstType;
6
7#[derive(Debug, Clone, Serialize)]
10pub struct InstIdRequest<'a> {
11 #[serde(rename = "instId")]
12 inst_id: Cow<'a, str>,
13}
14
15impl<'a> InstIdRequest<'a> {
16 pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
18 Self {
19 inst_id: inst_id.into(),
20 }
21 }
22}
23
24#[derive(Debug, Clone, Serialize)]
27pub struct TickersRequest<'a> {
28 #[serde(rename = "instType")]
29 inst_type: InstType,
30 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
31 inst_family: Option<Cow<'a, str>>,
32}
33
34impl<'a> TickersRequest<'a> {
35 pub fn new(inst_type: InstType) -> Self {
37 Self {
38 inst_type,
39 inst_family: None,
40 }
41 }
42
43 pub fn inst_family(mut self, inst_family: impl Into<Cow<'a, str>>) -> Self {
45 self.inst_family = Some(inst_family.into());
46 self
47 }
48}
49
50#[derive(Debug, Clone, Default, Serialize)]
52pub struct IndexTickersRequest<'a> {
53 #[serde(rename = "quoteCcy", skip_serializing_if = "Option::is_none")]
54 quote_ccy: Option<Cow<'a, str>>,
55 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
56 inst_id: Option<Cow<'a, str>>,
57}
58
59impl<'a> IndexTickersRequest<'a> {
60 pub fn new() -> Self {
62 Self::default()
63 }
64
65 pub fn quote_currency(mut self, quote_ccy: impl Into<Cow<'a, str>>) -> Self {
67 self.quote_ccy = Some(quote_ccy.into());
68 self
69 }
70
71 pub fn inst_id(mut self, inst_id: impl Into<Cow<'a, str>>) -> Self {
73 self.inst_id = Some(inst_id.into());
74 self
75 }
76}
77
78#[derive(Debug, Clone, Serialize)]
80pub struct OrderBookRequest<'a> {
81 #[serde(rename = "instId")]
82 inst_id: Cow<'a, str>,
83 #[serde(skip_serializing_if = "Option::is_none")]
84 sz: Option<u32>,
85}
86
87impl<'a> OrderBookRequest<'a> {
88 pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
90 Self {
91 inst_id: inst_id.into(),
92 sz: None,
93 }
94 }
95
96 pub fn size(mut self, sz: u32) -> Self {
98 self.sz = Some(sz);
99 self
100 }
101}
102
103#[derive(Debug, Clone, Serialize)]
105pub struct CandlesRequest<'a> {
106 #[serde(rename = "instId")]
107 inst_id: Cow<'a, str>,
108 #[serde(skip_serializing_if = "Option::is_none")]
109 bar: Option<Cow<'a, str>>,
110 #[serde(skip_serializing_if = "Option::is_none")]
111 limit: Option<u32>,
112}
113
114impl<'a> CandlesRequest<'a> {
115 pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
117 Self {
118 inst_id: inst_id.into(),
119 bar: None,
120 limit: None,
121 }
122 }
123
124 pub fn bar(mut self, bar: impl Into<Cow<'a, str>>) -> Self {
126 self.bar = Some(bar.into());
127 self
128 }
129
130 pub fn limit(mut self, limit: u32) -> Self {
132 self.limit = Some(limit);
133 self
134 }
135}
136
137#[derive(Debug, Clone, Serialize)]
139pub struct TradesRequest<'a> {
140 #[serde(rename = "instId")]
141 inst_id: Cow<'a, str>,
142 #[serde(skip_serializing_if = "Option::is_none")]
143 limit: Option<u32>,
144}
145
146impl<'a> TradesRequest<'a> {
147 pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
149 Self {
150 inst_id: inst_id.into(),
151 limit: None,
152 }
153 }
154
155 pub fn limit(mut self, limit: u32) -> Self {
157 self.limit = Some(limit);
158 self
159 }
160}
161
162#[derive(Debug, Clone, Serialize)]
164pub struct InstFamilyRequest<'a> {
165 #[serde(rename = "instFamily")]
166 inst_family: Cow<'a, str>,
167}
168
169impl<'a> InstFamilyRequest<'a> {
170 pub fn new(inst_family: impl Into<Cow<'a, str>>) -> Self {
172 Self {
173 inst_family: inst_family.into(),
174 }
175 }
176}
177
178#[derive(Debug, Clone, Serialize)]
180pub struct IndexRequest<'a> {
181 index: Cow<'a, str>,
182}
183
184impl<'a> IndexRequest<'a> {
185 pub fn new(index: impl Into<Cow<'a, str>>) -> Self {
187 Self {
188 index: index.into(),
189 }
190 }
191}
192
193#[derive(Debug, Clone, Serialize)]
195pub struct CandlesticksRequest<'a> {
196 #[serde(rename = "instId")]
197 inst_id: Cow<'a, str>,
198 #[serde(skip_serializing_if = "Option::is_none")]
199 after: Option<Cow<'a, str>>,
200 #[serde(skip_serializing_if = "Option::is_none")]
201 before: Option<Cow<'a, str>>,
202 #[serde(skip_serializing_if = "Option::is_none")]
203 bar: Option<Cow<'a, str>>,
204 #[serde(skip_serializing_if = "Option::is_none")]
205 limit: Option<u32>,
206}
207
208impl<'a> CandlesticksRequest<'a> {
209 pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
211 Self {
212 inst_id: inst_id.into(),
213 after: None,
214 before: None,
215 bar: None,
216 limit: None,
217 }
218 }
219
220 pub fn after(mut self, after: impl Into<Cow<'a, str>>) -> Self {
222 self.after = Some(after.into());
223 self
224 }
225
226 pub fn before(mut self, before: impl Into<Cow<'a, str>>) -> Self {
228 self.before = Some(before.into());
229 self
230 }
231
232 pub fn bar(mut self, bar: impl Into<Cow<'a, str>>) -> Self {
234 self.bar = Some(bar.into());
235 self
236 }
237
238 pub fn limit(mut self, limit: u32) -> Self {
240 self.limit = Some(limit);
241 self
242 }
243}
244
245#[derive(Debug, Clone, Serialize)]
247pub struct HistoryTradesRequest<'a> {
248 #[serde(rename = "instId")]
249 inst_id: Cow<'a, str>,
250 #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
251 trade_type: Option<Cow<'a, str>>,
252 #[serde(skip_serializing_if = "Option::is_none")]
253 after: Option<Cow<'a, str>>,
254 #[serde(skip_serializing_if = "Option::is_none")]
255 before: Option<Cow<'a, str>>,
256 #[serde(skip_serializing_if = "Option::is_none")]
257 limit: Option<u32>,
258}
259
260impl<'a> HistoryTradesRequest<'a> {
261 pub fn new(inst_id: impl Into<Cow<'a, str>>) -> Self {
263 Self {
264 inst_id: inst_id.into(),
265 trade_type: None,
266 after: None,
267 before: None,
268 limit: None,
269 }
270 }
271
272 pub fn trade_type(mut self, trade_type: impl Into<Cow<'a, str>>) -> Self {
274 self.trade_type = Some(trade_type.into());
275 self
276 }
277
278 pub fn after(mut self, after: impl Into<Cow<'a, str>>) -> Self {
280 self.after = Some(after.into());
281 self
282 }
283
284 pub fn before(mut self, before: impl Into<Cow<'a, str>>) -> Self {
286 self.before = Some(before.into());
287 self
288 }
289
290 pub fn limit(mut self, limit: u32) -> Self {
292 self.limit = Some(limit);
293 self
294 }
295}