rust-okx 0.6.0

Async Rust client for the OKX v5 REST API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
use serde::Serialize;

/// Account type used in sub-account asset transfers.
#[derive(Debug, Clone, Copy, Serialize)]
pub enum SubAccountType {
    /// Funding account (wire value `"6"`).
    #[serde(rename = "6")]
    Funding,
    /// Trading account (wire value `"18"`).
    #[serde(rename = "18")]
    Trading,
}

/// Query parameters for [`SubAccount::get_subaccount_list`].
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SubAccountListRequest {
    #[serde(skip_serializing_if = "Option::is_none")]
    enable: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    sub_acct: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    after: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    before: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    limit: Option<u32>,
}

impl SubAccountListRequest {
    /// Start with no filters applied.
    pub fn new() -> Self {
        Self::default()
    }

    /// Filter by enabled/disabled status.
    pub fn enable(mut self, enable: bool) -> Self {
        self.enable = Some(enable);
        self
    }

    /// Filter to a specific sub-account by name.
    pub fn sub_acct(mut self, sub_acct: impl Into<String>) -> Self {
        self.sub_acct = Some(sub_acct.into());
        self
    }

    /// Return results with UID older than this value.
    pub fn after(mut self, after: impl Into<String>) -> Self {
        self.after = Some(after.into());
        self
    }

    /// Return results with UID newer than this value.
    pub fn before(mut self, before: impl Into<String>) -> Self {
        self.before = Some(before.into());
        self
    }

    /// Maximum number of results (default 100, max 100).
    pub fn limit(mut self, limit: u32) -> Self {
        self.limit = Some(limit);
        self
    }
}

/// Query parameters for [`SubAccount::get_subaccount_apikeys`].
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SubAccountApiKeysRequest {
    sub_acct: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    api_key: Option<String>,
}

impl SubAccountApiKeysRequest {
    /// List all API keys for `sub_acct`.
    pub fn new(sub_acct: impl Into<String>) -> Self {
        Self {
            sub_acct: sub_acct.into(),
            api_key: None,
        }
    }

    /// Retrieve a specific API key.
    pub fn api_key(mut self, api_key: impl Into<String>) -> Self {
        self.api_key = Some(api_key.into());
        self
    }
}

/// Query parameters for [`SubAccount::get_subaccount_trading_balances`].
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SubAccountTradingBalancesRequest {
    sub_acct: String,
}

impl SubAccountTradingBalancesRequest {
    /// Query trading-account balances for `sub_acct`.
    pub fn new(sub_acct: impl Into<String>) -> Self {
        Self {
            sub_acct: sub_acct.into(),
        }
    }
}

/// Query parameters for [`SubAccount::get_subaccount_funding_balances`].
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SubAccountFundingBalancesRequest {
    sub_acct: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    ccy: Option<String>,
}

impl SubAccountFundingBalancesRequest {
    /// Query funding-account balances for `sub_acct`.
    pub fn new(sub_acct: impl Into<String>) -> Self {
        Self {
            sub_acct: sub_acct.into(),
            ccy: None,
        }
    }

    /// Filter by currency.
    pub fn ccy(mut self, ccy: impl Into<String>) -> Self {
        self.ccy = Some(ccy.into());
        self
    }
}

/// Query parameters for [`SubAccount::get_subaccount_max_withdrawal`].
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SubAccountMaxWithdrawalRequest {
    sub_acct: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    ccy: Option<String>,
}

impl SubAccountMaxWithdrawalRequest {
    /// Query maximum withdrawal for `sub_acct`.
    pub fn new(sub_acct: impl Into<String>) -> Self {
        Self {
            sub_acct: sub_acct.into(),
            ccy: None,
        }
    }

    /// Filter to a specific currency.
    pub fn ccy(mut self, ccy: impl Into<String>) -> Self {
        self.ccy = Some(ccy.into());
        self
    }
}

/// Request body for [`SubAccount::create_subaccount`].
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateSubAccountRequest {
    sub_acct: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    r#type: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    label: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pwd: Option<String>,
}

impl CreateSubAccountRequest {
    /// Create a sub-account with the given name.
    pub fn new(sub_acct: impl Into<String>) -> Self {
        Self {
            sub_acct: sub_acct.into(),
            r#type: None,
            label: None,
            pwd: None,
        }
    }

    /// Set the sub-account type.
    pub fn sub_type(mut self, sub_type: impl Into<String>) -> Self {
        self.r#type = Some(sub_type.into());
        self
    }

    /// Set a display label for the sub-account.
    pub fn label(mut self, label: impl Into<String>) -> Self {
        self.label = Some(label.into());
        self
    }

    /// Set the login password.
    pub fn pwd(mut self, pwd: impl Into<String>) -> Self {
        self.pwd = Some(pwd.into());
        self
    }
}

/// Request body for [`SubAccount::create_subaccount_apikey`].
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateSubAccountApiKeyRequest {
    sub_acct: String,
    label: String,
    passphrase: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    perm: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    ip: Option<String>,
}

impl CreateSubAccountApiKeyRequest {
    /// Create an API key for `sub_acct` with a label and passphrase.
    pub fn new(
        sub_acct: impl Into<String>,
        label: impl Into<String>,
        passphrase: impl Into<String>,
    ) -> Self {
        Self {
            sub_acct: sub_acct.into(),
            label: label.into(),
            passphrase: passphrase.into(),
            perm: None,
            ip: None,
        }
    }

    /// Set permissions (comma-separated, e.g. `"read_only,trade"`).
    pub fn perm(mut self, perm: impl Into<String>) -> Self {
        self.perm = Some(perm.into());
        self
    }

    /// Restrict to specific IP addresses (comma-separated).
    pub fn ip(mut self, ip: impl Into<String>) -> Self {
        self.ip = Some(ip.into());
        self
    }
}

/// Request body for [`SubAccount::modify_subaccount_apikey`].
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ModifySubAccountApiKeyRequest {
    sub_acct: String,
    api_key: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    label: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    perm: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    ip: Option<String>,
}

impl ModifySubAccountApiKeyRequest {
    /// Modify the API key identified by `api_key` on `sub_acct`.
    pub fn new(sub_acct: impl Into<String>, api_key: impl Into<String>) -> Self {
        Self {
            sub_acct: sub_acct.into(),
            api_key: api_key.into(),
            label: None,
            perm: None,
            ip: None,
        }
    }

    /// Change the label.
    pub fn label(mut self, label: impl Into<String>) -> Self {
        self.label = Some(label.into());
        self
    }

    /// Change permissions (comma-separated).
    pub fn perm(mut self, perm: impl Into<String>) -> Self {
        self.perm = Some(perm.into());
        self
    }

    /// Change allowed IP addresses (comma-separated).
    pub fn ip(mut self, ip: impl Into<String>) -> Self {
        self.ip = Some(ip.into());
        self
    }
}

/// Request body for [`SubAccount::delete_subaccount_apikey`].
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DeleteSubAccountApiKeyRequest {
    sub_acct: String,
    api_key: String,
}

impl DeleteSubAccountApiKeyRequest {
    /// Delete the API key identified by `api_key` from `sub_acct`.
    pub fn new(sub_acct: impl Into<String>, api_key: impl Into<String>) -> Self {
        Self {
            sub_acct: sub_acct.into(),
            api_key: api_key.into(),
        }
    }
}

/// Request body for [`SubAccount::transfer_between_subaccounts`].
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SubAccountTransferRequest {
    ccy: String,
    amt: String,
    from: SubAccountType,
    to: SubAccountType,
    from_sub_account: String,
    to_sub_account: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    loan_trans: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    omit_pos_risk: Option<String>,
}

impl SubAccountTransferRequest {
    /// Transfer `amt` of `ccy` between sub-accounts.
    ///
    /// `from` / `to` select the account type on each side:
    /// [`SubAccountType::Funding`] or [`SubAccountType::Trading`].
    pub fn new(
        ccy: impl Into<String>,
        amt: impl Into<String>,
        from: SubAccountType,
        to: SubAccountType,
        from_sub_account: impl Into<String>,
        to_sub_account: impl Into<String>,
    ) -> Self {
        Self {
            ccy: ccy.into(),
            amt: amt.into(),
            from,
            to,
            from_sub_account: from_sub_account.into(),
            to_sub_account: to_sub_account.into(),
            loan_trans: None,
            omit_pos_risk: None,
        }
    }

    /// Whether to transfer with borrowing.
    pub fn loan_trans(mut self, loan_trans: bool) -> Self {
        self.loan_trans = Some(loan_trans);
        self
    }

    /// Whether to ignore position risk when transferring.
    pub fn omit_pos_risk(mut self, omit_pos_risk: impl Into<String>) -> Self {
        self.omit_pos_risk = Some(omit_pos_risk.into());
        self
    }
}

/// Request body for [`SubAccount::set_subaccount_transfer_out`].
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SetTransferOutRequest {
    sub_acct: String,
    // True is default value.
    can_trans_out: bool,
}

impl SetTransferOutRequest {
    /// Enable or disable transfers out for `sub_acct`.
    pub fn new(sub_acct: impl Into<String>) -> Self {
        Self {
            sub_acct: sub_acct.into(),
            can_trans_out: true,
        }
    }

    ///Filter by can_trans_out
    pub fn can_trans_out(mut self, can_trans_out: bool) -> Self {
        self.can_trans_out = can_trans_out;
        self
    }
}

/// Query parameters for [`SubAccount::get_subaccount_bills`].
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SubAccountBillsRequest {
    #[serde(skip_serializing_if = "Option::is_none")]
    ccy: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    r#type: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    sub_acct: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    after: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    before: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    limit: Option<u32>,
}

impl SubAccountBillsRequest {
    /// Start with no filters applied.
    pub fn new() -> Self {
        Self::default()
    }

    /// Filter by currency.
    pub fn ccy(mut self, ccy: impl Into<String>) -> Self {
        self.ccy = Some(ccy.into());
        self
    }

    /// Filter by bill type.
    pub fn bill_type(mut self, r#type: impl Into<String>) -> Self {
        self.r#type = Some(r#type.into());
        self
    }

    /// Filter by sub-account name.
    pub fn sub_acct(mut self, sub_acct: impl Into<String>) -> Self {
        self.sub_acct = Some(sub_acct.into());
        self
    }

    /// Return results older than this bill ID.
    pub fn after(mut self, after: impl Into<String>) -> Self {
        self.after = Some(after.into());
        self
    }

    /// Return results newer than this bill ID.
    pub fn before(mut self, before: impl Into<String>) -> Self {
        self.before = Some(before.into());
        self
    }

    /// Maximum number of results (default 100, max 100).
    pub fn limit(mut self, limit: u32) -> Self {
        self.limit = Some(limit);
        self
    }
}

/// Query parameters for [`SubAccount::get_subaccount_managed_bills`].
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ManagedSubAccountBillsRequest {
    #[serde(skip_serializing_if = "Option::is_none")]
    ccy: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    r#type: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    sub_acct: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    sub_uid: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    after: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    before: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    limit: Option<u32>,
}

impl ManagedSubAccountBillsRequest {
    /// Start with no filters applied.
    pub fn new() -> Self {
        Self::default()
    }

    /// Filter by currency.
    pub fn ccy(mut self, ccy: impl Into<String>) -> Self {
        self.ccy = Some(ccy.into());
        self
    }

    /// Filter by bill type.
    pub fn bill_type(mut self, r#type: impl Into<String>) -> Self {
        self.r#type = Some(r#type.into());
        self
    }

    /// Filter by sub-account name.
    pub fn sub_acct(mut self, sub_acct: impl Into<String>) -> Self {
        self.sub_acct = Some(sub_acct.into());
        self
    }

    /// Filter by sub-account UID.
    pub fn sub_uid(mut self, sub_uid: impl Into<String>) -> Self {
        self.sub_uid = Some(sub_uid.into());
        self
    }

    /// Return results older than this bill ID.
    pub fn after(mut self, after: impl Into<String>) -> Self {
        self.after = Some(after.into());
        self
    }

    /// Return results newer than this bill ID.
    pub fn before(mut self, before: impl Into<String>) -> Self {
        self.before = Some(before.into());
        self
    }

    /// Maximum number of results (default 100, max 100).
    pub fn limit(mut self, limit: u32) -> Self {
        self.limit = Some(limit);
        self
    }
}

/// Query parameters for [`SubAccount::get_entrust_subaccount_list`].
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct EntrustSubAccountListRequest {
    #[serde(skip_serializing_if = "Option::is_none")]
    sub_acct: Option<String>,
}