rust_okx/api/public_data/requests/
edge.rs1use std::borrow::Cow;
2
3use serde::Serialize;
4
5#[derive(Debug, Clone, Serialize)]
7pub struct OptionSummaryRequest<'a> {
8 #[serde(rename = "instFamily")]
9 inst_family: Cow<'a, str>,
10 #[serde(rename = "expTime", skip_serializing_if = "Option::is_none")]
11 exp_time: Option<Cow<'a, str>>,
12}
13
14impl<'a> OptionSummaryRequest<'a> {
15 pub fn new(inst_family: impl Into<Cow<'a, str>>) -> Self {
17 Self {
18 inst_family: inst_family.into(),
19 exp_time: None,
20 }
21 }
22
23 pub fn expiration(mut self, value: impl Into<Cow<'a, str>>) -> Self {
25 self.exp_time = Some(value.into());
26 self
27 }
28}
29
30#[derive(Debug, Clone, Default, Serialize)]
32pub struct InterestRateLoanQuotaRequest {}
33
34impl InterestRateLoanQuotaRequest {
35 pub fn new() -> Self {
37 Self::default()
38 }
39}
40
41#[derive(Debug, Clone, Serialize)]
43pub struct InstrumentTickBandsRequest<'a> {
44 #[serde(rename = "instType")]
45 inst_type: Cow<'a, str>,
46}
47
48impl<'a> InstrumentTickBandsRequest<'a> {
49 pub fn new(inst_type: impl Into<Cow<'a, str>>) -> Self {
51 Self {
52 inst_type: inst_type.into(),
53 }
54 }
55}
56
57#[derive(Debug, Clone, Serialize)]
59pub struct UnderlyingRequest<'a> {
60 #[serde(rename = "instType")]
61 inst_type: Cow<'a, str>,
62}
63
64impl<'a> UnderlyingRequest<'a> {
65 pub fn new(inst_type: impl Into<Cow<'a, str>>) -> Self {
67 Self {
68 inst_type: inst_type.into(),
69 }
70 }
71}
72
73#[derive(Debug, Clone, Default, Serialize)]
75pub struct PublicOptionTradesRequest<'a> {
76 #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
77 inst_id: Option<Cow<'a, str>>,
78 #[serde(rename = "instFamily", skip_serializing_if = "Option::is_none")]
79 inst_family: Option<Cow<'a, str>>,
80 #[serde(rename = "optType", skip_serializing_if = "Option::is_none")]
81 option_type: Option<Cow<'a, str>>,
82}
83
84impl<'a> PublicOptionTradesRequest<'a> {
85 pub fn new() -> Self {
87 Self::default()
88 }
89
90 pub fn inst_id(mut self, value: impl Into<Cow<'a, str>>) -> Self {
92 self.inst_id = Some(value.into());
93 self
94 }
95
96 pub fn inst_family(mut self, value: impl Into<Cow<'a, str>>) -> Self {
98 self.inst_family = Some(value.into());
99 self
100 }
101
102 pub fn option_type(mut self, value: impl Into<Cow<'a, str>>) -> Self {
104 self.option_type = Some(value.into());
105 self
106 }
107}
108
109#[derive(Debug, Clone, Default, Serialize)]
111pub struct MarketDataHistoryRequest<'a> {
112 #[serde(skip_serializing_if = "Option::is_none")]
113 module: Option<Cow<'a, str>>,
114 #[serde(rename = "instType", skip_serializing_if = "Option::is_none")]
115 inst_type: Option<Cow<'a, str>>,
116 #[serde(rename = "instIdList", skip_serializing_if = "Option::is_none")]
117 inst_id_list: Option<Cow<'a, str>>,
118 #[serde(rename = "dateAggrType", skip_serializing_if = "Option::is_none")]
119 date_aggr_type: Option<Cow<'a, str>>,
120 #[serde(skip_serializing_if = "Option::is_none")]
121 begin: Option<Cow<'a, str>>,
122 #[serde(skip_serializing_if = "Option::is_none")]
123 end: Option<Cow<'a, str>>,
124}
125
126impl<'a> MarketDataHistoryRequest<'a> {
127 pub fn new() -> Self {
129 Self::default()
130 }
131
132 pub fn module(mut self, value: impl Into<Cow<'a, str>>) -> Self {
134 self.module = Some(value.into());
135 self
136 }
137
138 pub fn inst_type(mut self, value: impl Into<Cow<'a, str>>) -> Self {
140 self.inst_type = Some(value.into());
141 self
142 }
143
144 pub fn inst_id_list(mut self, value: impl Into<Cow<'a, str>>) -> Self {
146 self.inst_id_list = Some(value.into());
147 self
148 }
149
150 pub fn date_aggregation(mut self, value: impl Into<Cow<'a, str>>) -> Self {
152 self.date_aggr_type = Some(value.into());
153 self
154 }
155
156 pub fn begin(mut self, value: impl Into<Cow<'a, str>>) -> Self {
158 self.begin = Some(value.into());
159 self
160 }
161
162 pub fn end(mut self, value: impl Into<Cow<'a, str>>) -> Self {
164 self.end = Some(value.into());
165 self
166 }
167}
168
169#[cfg(test)]
170mod tests {
171 use super::*;
172
173 #[test]
174 fn market_history_uses_okx_field_names() {
175 let request = MarketDataHistoryRequest::new()
176 .module("2")
177 .inst_type("SPOT")
178 .inst_id_list("BTC-USDT")
179 .date_aggregation("daily");
180 let value = serde_json::to_value(request).unwrap();
181 assert_eq!(value["instType"], "SPOT");
182 assert_eq!(value["instIdList"], "BTC-USDT");
183 assert_eq!(value["dateAggrType"], "daily");
184 }
185}