Skip to main content

rust_okx/api/funding/
requests.rs

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