okx-client 0.1.2

Async Rust client for the OKX exchange API v5
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
use serde::Serialize;

use crate::types::enums::*;

/// Get balance request.
///
/// Retrieve a list of assets (with non-zero balance), remaining balance,
/// and available amount in the trading account.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetBalanceRequest {
    /// Single currency or comma-separated list of currencies, e.g. "BTC" or "BTC,ETH".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ccy: Option<String>,
}

/// Get positions request.
///
/// Retrieve information on your positions. When the account is in `net` mode,
/// `net` positions will be displayed, and when the account is in `long/short`
/// mode, `long` or `short` positions will be displayed.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetPositionsRequest {
    /// Instrument type.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inst_type: Option<InstrumentType>,
    /// Instrument ID, e.g. "BTC-USDT-SWAP".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inst_id: Option<String>,
    /// Position ID. Supports multiple IDs separated by commas (max 20).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pos_id: Option<String>,
}

/// Get positions history request.
///
/// Retrieve the updated position data for the last 3 months.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetPositionsHistoryRequest {
    /// Instrument type.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inst_type: Option<InstrumentType>,
    /// Instrument ID, e.g. "BTC-USD-SWAP".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inst_id: Option<String>,
    /// Margin mode.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mgn_mode: Option<MarginMode>,
    /// The type of closing position: 1 - Close position, 2 - Partially closed,
    /// 3 - Liquidation, 4 - Partial liquidation, 5 - ADL.
    #[serde(rename = "type")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub type_: Option<String>,
    /// Position ID.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pos_id: Option<String>,
    /// Pagination of data to return records earlier than the requested `posId`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub after: Option<String>,
    /// Pagination of data to return records newer than the requested `posId`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// Number of results per request. Maximum 100; default 100.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<String>,
}

/// Get account position risk request.
///
/// Get account position risk data.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetAccountPositionRiskRequest {
    /// Instrument type.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inst_type: Option<InstrumentType>,
}

/// Get bills detail request.
///
/// Retrieve the bills of the account. The bill refers to all transaction records
/// that result in changing of the balance of an account.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetBillsRequest {
    /// Instrument type.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inst_type: Option<InstrumentType>,
    /// Currency, e.g. "BTC".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ccy: Option<String>,
    /// Margin mode.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mgn_mode: Option<MarginMode>,
    /// Contract type.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ct_type: Option<String>,
    /// Bill type.
    #[serde(rename = "type")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub type_: Option<String>,
    /// Bill sub-type.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sub_type: Option<String>,
    /// Pagination of data to return records earlier than the requested `billId`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub after: Option<String>,
    /// Pagination of data to return records newer than the requested `billId`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// Number of results per request. Maximum 100; default 100.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<String>,
    /// Filter with a begin timestamp (Unix timestamp in milliseconds).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub begin: Option<String>,
    /// Filter with an end timestamp (Unix timestamp in milliseconds).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub end: Option<String>,
}

/// Set position mode request.
///
/// Set the position mode: `long_short_mode` or `net_mode`.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct SetPositionModeRequest {
    /// Position mode.
    pub pos_mode: PosMode,
}

/// Set leverage request.
///
/// Set the leverage for an instrument or a currency in a given margin mode.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct SetLeverageRequest {
    /// Instrument ID, e.g. "BTC-USDT-SWAP".
    /// Required when setting leverage for a specific instrument.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inst_id: Option<String>,
    /// Currency, e.g. "BTC". Required when setting leverage for a currency.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ccy: Option<String>,
    /// Leverage value.
    pub lever: String,
    /// Margin mode.
    pub mgn_mode: MarginMode,
    /// Position side. Required in `long_short_mode` under `cross` margin mode.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pos_side: Option<PositionSide>,
}

/// Get leverage request.
///
/// Get the leverage of an instrument.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetLeverageRequest {
    /// Instrument ID, e.g. "BTC-USDT-SWAP".
    pub inst_id: String,
    /// Margin mode.
    pub mgn_mode: MarginMode,
}

/// Get maximum buy/sell amount request.
///
/// Get the maximum tradeable amount for an instrument.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetMaxBuySellAmountRequest {
    /// Instrument ID, e.g. "BTC-USDT".
    pub inst_id: String,
    /// Trade mode: "cross", "isolated", "cash".
    pub td_mode: String,
    /// Currency, e.g. "BTC". Required in `cross` mode for `SPOT/MARGIN`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ccy: Option<String>,
    /// Price. Influences max buy amount in certain modes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub px: Option<String>,
    /// Leverage for the instrument.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub leverage: Option<String>,
    /// Whether to offset with spot positions. `true` or `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub un_spot_offset: Option<String>,
}

/// Get maximum available tradeable size request.
///
/// Get the maximum available size for an instrument.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetMaxAvailSizeRequest {
    /// Instrument ID, e.g. "BTC-USDT".
    pub inst_id: String,
    /// Trade mode: "cross", "isolated", "cash".
    pub td_mode: String,
    /// Currency, e.g. "BTC".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ccy: Option<String>,
    /// Whether to reduce position only.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reduce_only: Option<bool>,
    /// Whether to offset with spot positions.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub un_spot_offset: Option<String>,
    /// Quick margin type. Only applicable to Quick Margin Mode of isolated margin.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub quick_mgn_type: Option<String>,
}

/// Get maximum loan request.
///
/// Get the maximum loan amount for an instrument.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetMaxLoanRequest {
    /// Instrument ID, e.g. "BTC-USDT".
    pub inst_id: String,
    /// Margin mode.
    pub mgn_mode: MarginMode,
    /// Margin currency. Required for cross margin mode in
    /// multi-currency margin and portfolio margin.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mgn_ccy: Option<String>,
}

/// Get fee rates request.
///
/// Get the trading fee rate for an instrument type.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetFeeRatesRequest {
    /// Instrument type.
    pub inst_type: InstrumentType,
    /// Instrument ID, e.g. "BTC-USDT". Only applicable to `SPOT`/`MARGIN`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inst_id: Option<String>,
    /// Underlying, e.g. "BTC-USD". Only applicable to `FUTURES`/`SWAP`/`OPTION`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub uly: Option<String>,
    /// Instrument family, e.g. "BTC-USD". Only applicable to `FUTURES`/`SWAP`/`OPTION`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inst_family: Option<String>,
}

/// Get interest accrued request.
///
/// Get the interest accrued data.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetInterestAccruedRequest {
    /// Instrument ID, e.g. "BTC-USDT".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inst_id: Option<String>,
    /// Currency, e.g. "BTC".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ccy: Option<String>,
    /// Margin mode.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mgn_mode: Option<MarginMode>,
    /// Pagination of data to return records earlier than the requested timestamp.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub after: Option<String>,
    /// Pagination of data to return records newer than the requested timestamp.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// Number of results per request. Maximum 100; default 100.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<String>,
}

/// Set greeks display type request.
///
/// Set the display type of Greeks.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct SetGreeksRequest {
    /// Display type of Greeks.
    pub greeks_type: GreeksType,
}

/// Set isolated margin trading mode request.
///
/// Set the isolated margin trading settings for a given instrument type.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct SetIsolatedModeRequest {
    /// Isolated margin trading settings: "automatic" or "autonomy".
    pub iso_mode: String,
    /// Instrument type: "MARGIN" or "CONTRACTS".
    #[serde(rename = "type")]
    pub type_: String,
}

/// Get maximum withdrawals request.
///
/// Retrieve the maximum transferable amount.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetMaxWithdrawalsRequest {
    /// Currency, e.g. "BTC".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ccy: Option<String>,
}

/// Set MMP (Market Maker Protection) config request.
///
/// Set the MMP configuration for a given instrument family.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct SetMmpConfigRequest {
    /// Instrument family, e.g. "BTC-USD".
    pub inst_family: String,
    /// Time window (ms). MMP will be triggered if the order count exceeds
    /// `qtyLimit` within the time window.
    pub time_interval: String,
    /// Frozen period (ms). MMP frozen time after being triggered.
    pub frozen_interval: String,
    /// Quantity limit. The number of contracts that can be traded within the time window.
    pub qty_limit: String,
}

/// Get MMP config request.
///
/// Get the MMP configuration.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetMmpConfigRequest {
    /// Instrument family, e.g. "BTC-USD".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inst_family: Option<String>,
}

/// Set account level request.
///
/// Set the account level.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct SetAccountLevelRequest {
    /// Account level: "1" - Simple, "2" - Single-currency margin,
    /// "3" - Multi-currency margin, "4" - Portfolio margin.
    pub acct_lv: String,
}

/// Change position margin request.
///
/// Increase or decrease margin for an isolated position.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ChangePositionMarginRequest {
    /// Instrument ID, e.g. "BTC-USDT-SWAP".
    pub inst_id: String,
    /// Position side.
    pub pos_side: PositionSide,
    /// Operation: "add" to increase margin, "reduce" to decrease.
    #[serde(rename = "type")]
    pub type_: String,
    /// Amount to add or reduce.
    pub amt: String,
    /// Currency. Only applicable to `MARGIN`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ccy: Option<String>,
    /// Whether to automatically borrow funds when adding margin.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub auto: Option<bool>,
    /// Whether the transferred amount can be automatically used for borrowing.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub loan_trans: Option<bool>,
}

/// Borrow or repay in quick margin mode.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct BorrowRepayRequest {
    /// Currency, e.g. "BTC".
    pub ccy: String,
    /// Direction: "borrow" or "repay".
    pub side: String,
    /// Amount to borrow or repay.
    pub amt: String,
    /// Order ID for repayment. Required when `side` is "repay".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ord_id: Option<String>,
}

/// Get borrow/repay history request.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetBorrowRepayHistoryRequest {
    /// Currency, e.g. "BTC".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ccy: Option<String>,
    /// Pagination of data to return records earlier than the requested timestamp.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub after: Option<String>,
    /// Pagination of data to return records newer than the requested timestamp.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// Number of results per request. Maximum 100; default 100.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<String>,
}

/// Get greeks request.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetGreeksRequest {
    /// Currency, e.g. "BTC". Returns all currencies if omitted.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ccy: Option<String>,
}

/// Set auto loan request.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct SetAutoLoanRequest {
    /// Whether to enable automatic borrowing.
    pub auto_loan: bool,
}

#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetAccountBillSubtypesRequest {
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    pub type_: Option<String>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct BillsHistoryArchiveRequest {
    pub year: String,
    pub quarter: String,
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    pub type_: Option<String>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SetTradingConfigRequest {
    #[serde(rename = "type")]
    pub type_: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stgy_type: Option<String>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PrecheckSetDeltaNeutralRequest {
    pub stgy_type: String,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MovePositionFrom {
    pub pos_id: String,
    pub side: String,
    pub sz: String,
}

#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct MovePositionTo {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub td_mode: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pos_side: Option<PositionSide>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ccy: Option<String>,
}

#[derive(Debug, Clone, Serialize)]
pub struct MovePositionLeg {
    pub from: MovePositionFrom,
    pub to: MovePositionTo,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MovePositionsRequest {
    pub from_acct: String,
    pub to_acct: String,
    pub legs: Vec<MovePositionLeg>,
    pub client_id: String,
}

#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetMovePositionsHistoryRequest {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub block_td_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub client_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub begin_ts: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub end_ts: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub state: Option<String>,
}