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