Skip to main content

rust_okx/api/funding/
requests.rs

1use serde::Serialize;
2
3/// Request body for [`Funding::funds_transfer`].
4#[derive(Debug, Clone, Serialize)]
5#[serde(rename_all = "camelCase")]
6pub struct FundsTransferRequest {
7    ccy: String,
8    amt: String,
9    #[serde(rename = "from")]
10    from_account: String,
11    to: String,
12    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
13    transfer_type: Option<String>,
14    #[serde(rename = "subAcct", skip_serializing_if = "Option::is_none")]
15    sub_account: Option<String>,
16    #[serde(rename = "instId", skip_serializing_if = "Option::is_none")]
17    inst_id: Option<String>,
18    #[serde(rename = "toInstId", skip_serializing_if = "Option::is_none")]
19    to_inst_id: Option<String>,
20    #[serde(rename = "loanTrans", skip_serializing_if = "Option::is_none")]
21    loan_transfer: Option<String>,
22}
23
24impl FundsTransferRequest {
25    /// Create a funds-transfer request.
26    pub fn new(
27        ccy: impl Into<String>,
28        amt: impl Into<String>,
29        from_account: impl Into<String>,
30        to: impl Into<String>,
31    ) -> Self {
32        Self {
33            ccy: ccy.into(),
34            amt: amt.into(),
35            from_account: from_account.into(),
36            to: to.into(),
37            transfer_type: None,
38            sub_account: None,
39            inst_id: None,
40            to_inst_id: None,
41            loan_transfer: None,
42        }
43    }
44
45    /// Set transfer type, e.g. `0` for transfer within account.
46    pub fn transfer_type(mut self, transfer_type: impl Into<String>) -> Self {
47        self.transfer_type = Some(transfer_type.into());
48        self
49    }
50
51    /// Set sub-account name.
52    pub fn sub_account(mut self, sub_account: impl Into<String>) -> Self {
53        self.sub_account = Some(sub_account.into());
54        self
55    }
56
57    /// Set source instrument ID.
58    pub fn inst_id(mut self, inst_id: impl Into<String>) -> Self {
59        self.inst_id = Some(inst_id.into());
60        self
61    }
62
63    /// Set destination instrument ID.
64    pub fn to_inst_id(mut self, to_inst_id: impl Into<String>) -> Self {
65        self.to_inst_id = Some(to_inst_id.into());
66        self
67    }
68
69    /// Set whether this is a loan transfer.
70    pub fn loan_transfer(mut self, loan_transfer: impl Into<String>) -> Self {
71        self.loan_transfer = Some(loan_transfer.into());
72        self
73    }
74}
75
76/// Request body for [`Funding::withdrawal`].
77#[derive(Debug, Clone, Serialize)]
78#[serde(rename_all = "camelCase")]
79pub struct WithdrawalRequest {
80    ccy: String,
81    amt: String,
82    dest: String,
83    #[serde(rename = "toAddr")]
84    to_addr: String,
85    #[serde(skip_serializing_if = "Option::is_none")]
86    chain: Option<String>,
87    #[serde(rename = "areaCode", skip_serializing_if = "Option::is_none")]
88    area_code: Option<String>,
89    #[serde(rename = "clientId", skip_serializing_if = "Option::is_none")]
90    client_id: Option<String>,
91    #[serde(rename = "toAddrType", skip_serializing_if = "Option::is_none")]
92    to_addr_type: Option<String>,
93}
94
95impl WithdrawalRequest {
96    /// Create a withdrawal request.
97    pub fn new(
98        ccy: impl Into<String>,
99        amt: impl Into<String>,
100        dest: impl Into<String>,
101        to_addr: impl Into<String>,
102    ) -> Self {
103        Self {
104            ccy: ccy.into(),
105            amt: amt.into(),
106            dest: dest.into(),
107            to_addr: to_addr.into(),
108            chain: None,
109            area_code: None,
110            client_id: None,
111            to_addr_type: None,
112        }
113    }
114
115    /// Set withdrawal chain.
116    pub fn chain(mut self, chain: impl Into<String>) -> Self {
117        self.chain = Some(chain.into());
118        self
119    }
120
121    /// Set phone area code for internal withdrawals.
122    pub fn area_code(mut self, area_code: impl Into<String>) -> Self {
123        self.area_code = Some(area_code.into());
124        self
125    }
126
127    /// Set client withdrawal ID.
128    pub fn client_id(mut self, client_id: impl Into<String>) -> Self {
129        self.client_id = Some(client_id.into());
130        self
131    }
132
133    /// Set address type.
134    pub fn to_addr_type(mut self, to_addr_type: impl Into<String>) -> Self {
135        self.to_addr_type = Some(to_addr_type.into());
136        self
137    }
138}
139
140/// Query parameters for [`Funding::get_deposit_history`].
141#[derive(Debug, Clone, Default, Serialize)]
142#[serde(rename_all = "camelCase")]
143pub struct DepositHistoryRequest {
144    #[serde(skip_serializing_if = "Option::is_none")]
145    ccy: Option<String>,
146    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
147    deposit_type: Option<String>,
148    #[serde(skip_serializing_if = "Option::is_none")]
149    state: Option<String>,
150    #[serde(skip_serializing_if = "Option::is_none")]
151    after: Option<String>,
152    #[serde(skip_serializing_if = "Option::is_none")]
153    before: Option<String>,
154    #[serde(skip_serializing_if = "Option::is_none")]
155    limit: Option<u32>,
156    #[serde(rename = "txId", skip_serializing_if = "Option::is_none")]
157    tx_id: Option<String>,
158    #[serde(rename = "depId", skip_serializing_if = "Option::is_none")]
159    dep_id: Option<String>,
160    #[serde(rename = "fromWdId", skip_serializing_if = "Option::is_none")]
161    from_wd_id: Option<String>,
162}
163
164impl DepositHistoryRequest {
165    /// Create an empty deposit-history query.
166    pub fn new() -> Self {
167        Self::default()
168    }
169
170    /// Filter by currency.
171    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
172        self.ccy = Some(ccy.into());
173        self
174    }
175
176    /// Filter by deposit type.
177    pub fn deposit_type(mut self, deposit_type: impl Into<String>) -> Self {
178        self.deposit_type = Some(deposit_type.into());
179        self
180    }
181
182    /// Filter by state.
183    pub fn state(mut self, state: impl Into<String>) -> Self {
184        self.state = Some(state.into());
185        self
186    }
187
188    /// Page after the given ID.
189    pub fn after(mut self, after: impl Into<String>) -> Self {
190        self.after = Some(after.into());
191        self
192    }
193
194    /// Page before the given ID.
195    pub fn before(mut self, before: impl Into<String>) -> Self {
196        self.before = Some(before.into());
197        self
198    }
199
200    /// Set result limit.
201    pub fn limit(mut self, limit: u32) -> Self {
202        self.limit = Some(limit);
203        self
204    }
205
206    /// Filter by transaction ID.
207    pub fn tx_id(mut self, tx_id: impl Into<String>) -> Self {
208        self.tx_id = Some(tx_id.into());
209        self
210    }
211
212    /// Filter by deposit ID.
213    pub fn dep_id(mut self, dep_id: impl Into<String>) -> Self {
214        self.dep_id = Some(dep_id.into());
215        self
216    }
217
218    /// Filter by source withdrawal ID.
219    pub fn from_wd_id(mut self, from_wd_id: impl Into<String>) -> Self {
220        self.from_wd_id = Some(from_wd_id.into());
221        self
222    }
223}
224
225/// Query parameters for [`Funding::get_withdrawal_history`].
226#[derive(Debug, Clone, Default, Serialize)]
227#[serde(rename_all = "camelCase")]
228pub struct WithdrawalHistoryRequest {
229    #[serde(skip_serializing_if = "Option::is_none")]
230    ccy: Option<String>,
231    #[serde(rename = "wdId", skip_serializing_if = "Option::is_none")]
232    wd_id: Option<String>,
233    #[serde(rename = "clientId", skip_serializing_if = "Option::is_none")]
234    client_id: Option<String>,
235    #[serde(rename = "txId", skip_serializing_if = "Option::is_none")]
236    tx_id: Option<String>,
237    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
238    withdrawal_type: Option<String>,
239    #[serde(skip_serializing_if = "Option::is_none")]
240    state: Option<String>,
241    #[serde(skip_serializing_if = "Option::is_none")]
242    after: Option<String>,
243    #[serde(skip_serializing_if = "Option::is_none")]
244    before: Option<String>,
245    #[serde(skip_serializing_if = "Option::is_none")]
246    limit: Option<u32>,
247    #[serde(rename = "toAddrType", skip_serializing_if = "Option::is_none")]
248    to_addr_type: Option<String>,
249}
250
251impl WithdrawalHistoryRequest {
252    /// Create an empty withdrawal-history query.
253    pub fn new() -> Self {
254        Self::default()
255    }
256
257    /// Filter by currency.
258    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
259        self.ccy = Some(ccy.into());
260        self
261    }
262
263    /// Filter by withdrawal ID.
264    pub fn withdrawal_id(mut self, wd_id: impl Into<String>) -> Self {
265        self.wd_id = Some(wd_id.into());
266        self
267    }
268
269    /// Filter by client ID.
270    pub fn client_id(mut self, client_id: impl Into<String>) -> Self {
271        self.client_id = Some(client_id.into());
272        self
273    }
274
275    /// Filter by transaction ID.
276    pub fn tx_id(mut self, tx_id: impl Into<String>) -> Self {
277        self.tx_id = Some(tx_id.into());
278        self
279    }
280
281    /// Filter by withdrawal type.
282    pub fn withdrawal_type(mut self, withdrawal_type: impl Into<String>) -> Self {
283        self.withdrawal_type = Some(withdrawal_type.into());
284        self
285    }
286
287    /// Filter by state.
288    pub fn state(mut self, state: impl Into<String>) -> Self {
289        self.state = Some(state.into());
290        self
291    }
292
293    /// Page after the given ID.
294    pub fn after(mut self, after: impl Into<String>) -> Self {
295        self.after = Some(after.into());
296        self
297    }
298
299    /// Page before the given ID.
300    pub fn before(mut self, before: impl Into<String>) -> Self {
301        self.before = Some(before.into());
302        self
303    }
304
305    /// Set result limit.
306    pub fn limit(mut self, limit: u32) -> Self {
307        self.limit = Some(limit);
308        self
309    }
310
311    /// Filter by destination address type.
312    pub fn to_addr_type(mut self, to_addr_type: impl Into<String>) -> Self {
313        self.to_addr_type = Some(to_addr_type.into());
314        self
315    }
316}
317
318/// Query parameters for [`Funding::get_bills`].
319#[derive(Debug, Clone, Default, Serialize)]
320pub struct FundingBillsRequest {
321    #[serde(skip_serializing_if = "Option::is_none")]
322    ccy: Option<String>,
323    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
324    bill_type: Option<String>,
325    #[serde(skip_serializing_if = "Option::is_none")]
326    after: Option<String>,
327    #[serde(skip_serializing_if = "Option::is_none")]
328    before: Option<String>,
329    #[serde(skip_serializing_if = "Option::is_none")]
330    limit: Option<u32>,
331}
332
333impl FundingBillsRequest {
334    /// Create an empty funding-bills query.
335    pub fn new() -> Self {
336        Self::default()
337    }
338
339    /// Filter by currency.
340    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
341        self.ccy = Some(ccy.into());
342        self
343    }
344
345    /// Filter by bill type.
346    pub fn bill_type(mut self, bill_type: impl Into<String>) -> Self {
347        self.bill_type = Some(bill_type.into());
348        self
349    }
350
351    /// Page after the given bill ID.
352    pub fn after(mut self, after: impl Into<String>) -> Self {
353        self.after = Some(after.into());
354        self
355    }
356
357    /// Page before the given bill ID.
358    pub fn before(mut self, before: impl Into<String>) -> Self {
359        self.before = Some(before.into());
360        self
361    }
362
363    /// Set result limit.
364    pub fn limit(mut self, limit: u32) -> Self {
365        self.limit = Some(limit);
366        self
367    }
368}
369
370/// Query parameters for [`Funding::get_deposit_lightning`].
371#[derive(Debug, Clone, Serialize)]
372pub struct DepositLightningRequest {
373    ccy: String,
374    amt: String,
375    #[serde(skip_serializing_if = "Option::is_none")]
376    to: Option<String>,
377}
378
379impl DepositLightningRequest {
380    /// Create a Lightning deposit request.
381    pub fn new(ccy: impl Into<String>, amt: impl Into<String>) -> Self {
382        Self {
383            ccy: ccy.into(),
384            amt: amt.into(),
385            to: None,
386        }
387    }
388
389    /// Set recipient.
390    pub fn to(mut self, to: impl Into<String>) -> Self {
391        self.to = Some(to.into());
392        self
393    }
394}
395
396/// Request body for [`Funding::withdrawal_lightning`].
397#[derive(Debug, Clone, Serialize)]
398pub struct WithdrawalLightningRequest {
399    ccy: String,
400    invoice: String,
401    #[serde(skip_serializing_if = "Option::is_none")]
402    memo: Option<String>,
403}
404
405impl WithdrawalLightningRequest {
406    /// Create a Lightning withdrawal request.
407    pub fn new(ccy: impl Into<String>, invoice: impl Into<String>) -> Self {
408        Self {
409            ccy: ccy.into(),
410            invoice: invoice.into(),
411            memo: None,
412        }
413    }
414
415    /// Set withdrawal memo.
416    pub fn memo(mut self, memo: impl Into<String>) -> Self {
417        self.memo = Some(memo.into());
418        self
419    }
420}
421
422/// Query parameters for [`Funding::get_deposit_withdraw_status`].
423#[derive(Debug, Clone, Default, Serialize)]
424#[serde(rename_all = "camelCase")]
425pub struct DepositWithdrawStatusRequest {
426    #[serde(rename = "wdId", skip_serializing_if = "Option::is_none")]
427    wd_id: Option<String>,
428    #[serde(rename = "txId", skip_serializing_if = "Option::is_none")]
429    tx_id: Option<String>,
430    #[serde(skip_serializing_if = "Option::is_none")]
431    ccy: Option<String>,
432    #[serde(skip_serializing_if = "Option::is_none")]
433    to: Option<String>,
434    #[serde(skip_serializing_if = "Option::is_none")]
435    chain: Option<String>,
436}
437
438impl DepositWithdrawStatusRequest {
439    /// Create an empty deposit/withdrawal-status query.
440    pub fn new() -> Self {
441        Self::default()
442    }
443
444    /// Filter by withdrawal ID.
445    pub fn withdrawal_id(mut self, wd_id: impl Into<String>) -> Self {
446        self.wd_id = Some(wd_id.into());
447        self
448    }
449
450    /// Filter by transaction ID.
451    pub fn tx_id(mut self, tx_id: impl Into<String>) -> Self {
452        self.tx_id = Some(tx_id.into());
453        self
454    }
455
456    /// Filter by currency.
457    pub fn currency(mut self, ccy: impl Into<String>) -> Self {
458        self.ccy = Some(ccy.into());
459        self
460    }
461
462    /// Filter by destination address.
463    pub fn to(mut self, to: impl Into<String>) -> Self {
464        self.to = Some(to.into());
465        self
466    }
467
468    /// Filter by chain.
469    pub fn chain(mut self, chain: impl Into<String>) -> Self {
470        self.chain = Some(chain.into());
471        self
472    }
473}