Skip to main content

rust_okx/api/finance/requests/
staking.rs

1use serde::Serialize;
2
3/// Query parameters for `GET /api/v5/finance/staking-defi/offers`.
4#[derive(Debug, Clone, Default, Serialize)]
5pub struct StakingDefiOffersRequest {
6    #[serde(rename = "productId", skip_serializing_if = "Option::is_none")]
7    product_id: Option<String>,
8    #[serde(rename = "protocolType", skip_serializing_if = "Option::is_none")]
9    protocol_type: Option<String>,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    ccy: Option<String>,
12}
13
14impl StakingDefiOffersRequest {
15    /// Create an unfiltered offers query.
16    pub fn new() -> Self {
17        Self::default()
18    }
19
20    /// Restrict the response to one product ID.
21    pub fn product_id(mut self, value: impl Into<String>) -> Self {
22        self.product_id = Some(value.into());
23        self
24    }
25
26    /// Restrict the response to `staking` or `defi` products.
27    pub fn protocol_type(mut self, value: impl Into<String>) -> Self {
28        self.protocol_type = Some(value.into());
29        self
30    }
31
32    /// Restrict the response to one investment currency.
33    pub fn currency(mut self, value: impl Into<String>) -> Self {
34        self.ccy = Some(value.into());
35        self
36    }
37}
38
39/// Currency and amount invested into one On-chain Earn product.
40#[derive(Debug, Clone, Serialize)]
41pub struct StakingDefiInvestment {
42    ccy: String,
43    amt: String,
44}
45
46impl StakingDefiInvestment {
47    /// Create one investment item.
48    pub fn new(ccy: impl Into<String>, amt: impl Into<String>) -> Self {
49        Self {
50            ccy: ccy.into(),
51            amt: amt.into(),
52        }
53    }
54}
55
56/// Request body for `POST /api/v5/finance/staking-defi/purchase`.
57#[derive(Debug, Clone, Serialize)]
58pub struct StakingDefiPurchaseRequest {
59    #[serde(rename = "productId")]
60    product_id: String,
61    #[serde(rename = "investData")]
62    invest_data: Vec<StakingDefiInvestment>,
63    #[serde(skip_serializing_if = "Option::is_none")]
64    term: Option<String>,
65    #[serde(skip_serializing_if = "Option::is_none")]
66    tag: Option<String>,
67}
68
69impl StakingDefiPurchaseRequest {
70    /// Create a purchase with at least one currency/amount item.
71    pub fn new(product_id: impl Into<String>, invest_data: Vec<StakingDefiInvestment>) -> Self {
72        Self {
73            product_id: product_id.into(),
74            invest_data,
75            term: None,
76            tag: None,
77        }
78    }
79
80    /// Set the fixed product term when required by the selected product.
81    pub fn term(mut self, value: impl Into<String>) -> Self {
82        self.term = Some(value.into());
83        self
84    }
85
86    /// Set a case-sensitive ASCII alphanumeric tag of at most 16 characters.
87    pub fn tag(mut self, value: impl Into<String>) -> Self {
88        self.tag = Some(value.into());
89        self
90    }
91}
92
93/// Request body for `POST /api/v5/finance/staking-defi/redeem`.
94#[derive(Debug, Clone, Serialize)]
95pub struct StakingDefiRedeemRequest {
96    #[serde(rename = "ordId")]
97    ord_id: String,
98    #[serde(rename = "protocolType")]
99    protocol_type: String,
100    #[serde(rename = "allowEarlyRedeem", skip_serializing_if = "Option::is_none")]
101    allow_early_redeem: Option<bool>,
102}
103
104impl StakingDefiRedeemRequest {
105    /// Create a redemption for an existing order.
106    pub fn new(ord_id: impl Into<String>, protocol_type: impl Into<String>) -> Self {
107        Self {
108            ord_id: ord_id.into(),
109            protocol_type: protocol_type.into(),
110            allow_early_redeem: None,
111        }
112    }
113
114    /// Allow early redemption when the product supports it.
115    pub fn allow_early_redeem(mut self, value: bool) -> Self {
116        self.allow_early_redeem = Some(value);
117        self
118    }
119}
120
121/// Request body for `POST /api/v5/finance/staking-defi/cancel`.
122#[derive(Debug, Clone, Serialize)]
123pub struct StakingDefiCancelRequest {
124    #[serde(rename = "ordId")]
125    ord_id: String,
126    #[serde(rename = "protocolType")]
127    protocol_type: String,
128}
129
130impl StakingDefiCancelRequest {
131    /// Create a cancellation for a pending On-chain Earn order.
132    pub fn new(ord_id: impl Into<String>, protocol_type: impl Into<String>) -> Self {
133        Self {
134            ord_id: ord_id.into(),
135            protocol_type: protocol_type.into(),
136        }
137    }
138}
139
140/// Query parameters for `GET /api/v5/finance/staking-defi/orders-active`.
141#[derive(Debug, Clone, Default, Serialize)]
142pub struct StakingDefiActiveOrdersRequest {
143    #[serde(rename = "productId", skip_serializing_if = "Option::is_none")]
144    product_id: Option<String>,
145    #[serde(rename = "protocolType", skip_serializing_if = "Option::is_none")]
146    protocol_type: Option<String>,
147    #[serde(skip_serializing_if = "Option::is_none")]
148    ccy: Option<String>,
149    #[serde(skip_serializing_if = "Option::is_none")]
150    state: Option<String>,
151}
152
153impl StakingDefiActiveOrdersRequest {
154    /// Create an unfiltered active-orders query.
155    pub fn new() -> Self {
156        Self::default()
157    }
158
159    /// Filter by product ID.
160    pub fn product_id(mut self, value: impl Into<String>) -> Self {
161        self.product_id = Some(value.into());
162        self
163    }
164
165    /// Filter by `staking` or `defi` protocol type.
166    pub fn protocol_type(mut self, value: impl Into<String>) -> Self {
167        self.protocol_type = Some(value.into());
168        self
169    }
170
171    /// Filter by investment currency.
172    pub fn currency(mut self, value: impl Into<String>) -> Self {
173        self.ccy = Some(value.into());
174        self
175    }
176
177    /// Filter by OKX active-order state (`1`, `2`, `8`, `9`, or `13`).
178    pub fn state(mut self, value: impl Into<String>) -> Self {
179        self.state = Some(value.into());
180        self
181    }
182}
183
184/// Query parameters for `GET /api/v5/finance/staking-defi/orders-history`.
185#[derive(Debug, Clone, Default, Serialize)]
186pub struct StakingDefiOrderHistoryRequest {
187    #[serde(rename = "productId", skip_serializing_if = "Option::is_none")]
188    product_id: Option<String>,
189    #[serde(rename = "protocolType", skip_serializing_if = "Option::is_none")]
190    protocol_type: Option<String>,
191    #[serde(skip_serializing_if = "Option::is_none")]
192    ccy: Option<String>,
193    #[serde(skip_serializing_if = "Option::is_none")]
194    after: Option<String>,
195    #[serde(skip_serializing_if = "Option::is_none")]
196    before: Option<String>,
197    #[serde(skip_serializing_if = "Option::is_none")]
198    limit: Option<u32>,
199}
200
201impl StakingDefiOrderHistoryRequest {
202    /// Create an unfiltered order-history query.
203    pub fn new() -> Self {
204        Self::default()
205    }
206
207    /// Filter by product ID.
208    pub fn product_id(mut self, value: impl Into<String>) -> Self {
209        self.product_id = Some(value.into());
210        self
211    }
212
213    /// Filter by `staking` or `defi` protocol type.
214    pub fn protocol_type(mut self, value: impl Into<String>) -> Self {
215        self.protocol_type = Some(value.into());
216        self
217    }
218
219    /// Filter by investment currency.
220    pub fn currency(mut self, value: impl Into<String>) -> Self {
221        self.ccy = Some(value.into());
222        self
223    }
224
225    /// Return records before this order-ID cursor.
226    pub fn after(mut self, value: impl Into<String>) -> Self {
227        self.after = Some(value.into());
228        self
229    }
230
231    /// Return records after this order-ID cursor.
232    pub fn before(mut self, value: impl Into<String>) -> Self {
233        self.before = Some(value.into());
234        self
235    }
236
237    /// Set the result count from 1 through 100.
238    pub fn limit(mut self, value: u32) -> Self {
239        self.limit = Some(value);
240        self
241    }
242}