unicex 0.7.0__py3-none-any.whl → 0.8.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. unicex/_abc/__init__.py +4 -0
  2. unicex/_abc/decoder.py +18 -0
  3. unicex/_abc/uni_client.py +1 -1
  4. unicex/_base/__init__.py +2 -0
  5. unicex/_base/websocket.py +16 -4
  6. unicex/binance/adapter.py +1 -1
  7. unicex/binance/client.py +2 -2
  8. unicex/bitget/client.py +25 -10
  9. unicex/bybit/adapter.py +1 -1
  10. unicex/bybit/client.py +4 -4
  11. unicex/bybit/uni_client.py +2 -2
  12. unicex/bybit/websocket_manager.py +330 -2
  13. unicex/extra.py +84 -6
  14. unicex/gateio/adapter.py +2 -2
  15. unicex/gateio/client.py +1 -1
  16. unicex/hyperliquid/adapter.py +12 -1
  17. unicex/mexc/_spot_ws_proto/PrivateAccountV3Api_pb2.py +40 -0
  18. unicex/mexc/_spot_ws_proto/PrivateDealsV3Api_pb2.py +40 -0
  19. unicex/mexc/_spot_ws_proto/PrivateOrdersV3Api_pb2.py +40 -0
  20. unicex/mexc/_spot_ws_proto/PublicAggreBookTickerV3Api_pb2.py +40 -0
  21. unicex/mexc/_spot_ws_proto/PublicAggreDealsV3Api_pb2.py +42 -0
  22. unicex/mexc/_spot_ws_proto/PublicAggreDepthsV3Api_pb2.py +42 -0
  23. unicex/mexc/_spot_ws_proto/PublicBookTickerBatchV3Api_pb2.py +40 -0
  24. unicex/mexc/_spot_ws_proto/PublicBookTickerV3Api_pb2.py +40 -0
  25. unicex/mexc/_spot_ws_proto/PublicDealsV3Api_pb2.py +42 -0
  26. unicex/mexc/_spot_ws_proto/PublicFuture_pb2.py +105 -0
  27. unicex/mexc/_spot_ws_proto/PublicIncreaseDepthsBatchV3Api_pb2.py +40 -0
  28. unicex/mexc/_spot_ws_proto/PublicIncreaseDepthsV3Api_pb2.py +42 -0
  29. unicex/mexc/_spot_ws_proto/PublicLimitDepthsV3Api_pb2.py +42 -0
  30. unicex/mexc/_spot_ws_proto/PublicMiniTickerV3Api_pb2.py +40 -0
  31. unicex/mexc/_spot_ws_proto/PublicMiniTickersV3Api_pb2.py +40 -0
  32. unicex/mexc/_spot_ws_proto/PublicSpotKlineV3Api_pb2.py +40 -0
  33. unicex/mexc/_spot_ws_proto/PushDataV3ApiWrapper_pb2.py +40 -0
  34. unicex/mexc/_spot_ws_proto/__init__.py +332 -0
  35. unicex/mexc/adapter.py +2 -2
  36. unicex/mexc/client.py +2 -2
  37. unicex/okx/adapter.py +2 -2
  38. unicex/okx/client.py +2627 -43
  39. unicex/okx/uni_client.py +8 -8
  40. {unicex-0.7.0.dist-info → unicex-0.8.1.dist-info}/METADATA +4 -3
  41. {unicex-0.7.0.dist-info → unicex-0.8.1.dist-info}/RECORD +44 -25
  42. {unicex-0.7.0.dist-info → unicex-0.8.1.dist-info}/WHEEL +0 -0
  43. {unicex-0.7.0.dist-info → unicex-0.8.1.dist-info}/licenses/LICENSE +0 -0
  44. {unicex-0.7.0.dist-info → unicex-0.8.1.dist-info}/top_level.txt +0 -0
unicex/okx/client.py CHANGED
@@ -16,6 +16,18 @@ class Client(BaseClient):
16
16
  _BASE_URL: str = "https://www.okx.com"
17
17
  """Базовый URL для REST API OKX."""
18
18
 
19
+ def is_authorized(self) -> bool:
20
+ """Проверяет наличие API‑ключей у клиента.
21
+
22
+ Возвращает:
23
+ `bool`: Признак наличия ключей.
24
+ """
25
+ return (
26
+ self._api_key is not None
27
+ and self._api_secret is not None
28
+ and self._api_passphrase is not None
29
+ )
30
+
19
31
  def _get_timestamp(self) -> str:
20
32
  """Генерирует timestamp в формате OKX (ISO с миллисекундами и Z).
21
33
 
@@ -51,6 +63,11 @@ class Client(BaseClient):
51
63
  - `timestamp (str)`: Временная метка в формате OKX.
52
64
  - `signature (str)`: Подпись в формате base64.
53
65
  """
66
+ if not self.is_authorized():
67
+ raise NotAuthorized(
68
+ "Api key and api secret and api passphrase is required to private endpoints"
69
+ )
70
+
54
71
  timestamp = self._get_timestamp()
55
72
 
56
73
  # Формируем query string для GET запросов
@@ -82,16 +99,15 @@ class Client(BaseClient):
82
99
  `dict[str, str]`: Словарь заголовков запроса.
83
100
  """
84
101
  headers = {"Content-Type": "application/json", "Accept": "application/json"}
85
- if self._api_key: # type: ignore[attr-defined]
86
- headers.update(
87
- {
88
- "OK-ACCESS-KEY": self._api_key, # type: ignore[attr-defined]
89
- "OK-ACCESS-SIGN": signature,
90
- "OK-ACCESS-TIMESTAMP": timestamp,
91
- "OK-ACCESS-PASSPHRASE": self._api_passphrase, # type: ignore[attr-defined]
92
- "x-simulated-trading": "0",
93
- }
94
- )
102
+ headers.update(
103
+ {
104
+ "OK-ACCESS-KEY": self._api_key, # type: ignore[attr-defined]
105
+ "OK-ACCESS-SIGN": signature,
106
+ "OK-ACCESS-TIMESTAMP": timestamp,
107
+ "OK-ACCESS-PASSPHRASE": self._api_passphrase, # type: ignore[attr-defined]
108
+ "x-simulated-trading": "0",
109
+ }
110
+ )
95
111
  return headers
96
112
 
97
113
  def _prepare_request_params(
@@ -134,11 +150,6 @@ class Client(BaseClient):
134
150
 
135
151
  headers = None
136
152
  if signed:
137
- if not self._api_key or not self._api_secret or not self._api_passphrase:
138
- raise NotAuthorized(
139
- "API key, secret, and passphrase are required for private endpoints"
140
- )
141
-
142
153
  timestamp, signature = self._sign_message(method, endpoint, params, body)
143
154
  headers = self._get_headers(timestamp, signature)
144
155
  return url, params, body, headers
@@ -205,76 +216,2649 @@ class Client(BaseClient):
205
216
  method=method, endpoint=endpoint, params=params, data=data, signed=signed
206
217
  )
207
218
 
208
- # topic: Order Book Trading
209
- # sub-topic: Market Data
219
+ # topic: Trading Account
210
220
 
211
- async def tickers(
221
+ async def get_account_instruments(
212
222
  self,
213
- inst_type: Literal["SPOT", "SWAP", "FUTURES", "OPTION"],
214
- inst_family: Literal["FUTURES", "SWAP", "OPTION"] | None = None,
223
+ inst_type: Literal["SPOT", "MARGIN", "SWAP", "FUTURES", "OPTION"],
224
+ inst_family: str | None = None,
225
+ inst_id: str | None = None,
215
226
  ) -> dict:
216
- """Получение информации о тикерах.
217
-
218
- https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-tickers
227
+ """Получение доступных инструментов аккаунта.
219
228
 
229
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-instruments
220
230
  """
221
231
  params = {
222
232
  "instType": inst_type,
223
233
  "instFamily": inst_family,
234
+ "instId": inst_id,
224
235
  }
225
- return await self._make_request("GET", endpoint="/api/v5/market/tickers", params=params)
226
236
 
227
- async def candles(
237
+ return await self._make_request(
238
+ "GET",
239
+ endpoint="/api/v5/account/instruments",
240
+ params=params,
241
+ signed=True,
242
+ )
243
+
244
+ async def get_balance(self, ccy: str | None = None) -> dict:
245
+ """Получение баланса аккаунта.
246
+
247
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-balance
248
+ """
249
+ params = {
250
+ "ccy": ccy,
251
+ }
252
+
253
+ return await self._make_request(
254
+ "GET",
255
+ endpoint="/api/v5/account/balance",
256
+ params=params,
257
+ signed=True,
258
+ )
259
+
260
+ async def get_positions(
228
261
  self,
229
- inst_id: str,
230
- bar: str | None = None,
262
+ inst_type: Literal["MARGIN", "SWAP", "FUTURES", "OPTION"] | None = None,
263
+ inst_id: str | None = None,
264
+ pos_id: str | None = None,
265
+ ) -> dict:
266
+ """Получение текущих позиций аккаунта.
267
+
268
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-positions
269
+ """
270
+ params = {
271
+ "instType": inst_type,
272
+ "instId": inst_id,
273
+ "posId": pos_id,
274
+ }
275
+
276
+ return await self._make_request(
277
+ "GET",
278
+ endpoint="/api/v5/account/positions",
279
+ params=params,
280
+ signed=True,
281
+ )
282
+
283
+ async def get_positions_history(
284
+ self,
285
+ inst_type: Literal["MARGIN", "SWAP", "FUTURES", "OPTION"] | None = None,
286
+ inst_id: str | None = None,
287
+ mgn_mode: Literal["cross", "isolated"] | None = None,
288
+ type_: str | None = None,
289
+ pos_id: str | None = None,
231
290
  after: int | None = None,
232
291
  before: int | None = None,
233
292
  limit: int | None = None,
234
293
  ) -> dict:
235
- """Получение свечей.
294
+ """Получение истории позиций аккаунта.
236
295
 
237
- https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-candlesticks
296
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-positions-history
238
297
  """
239
298
  params = {
299
+ "instType": inst_type,
240
300
  "instId": inst_id,
241
- "bar": bar,
301
+ "mgnMode": mgn_mode,
302
+ "type": type_,
303
+ "posId": pos_id,
242
304
  "after": after,
243
305
  "before": before,
244
306
  "limit": limit,
245
307
  }
246
- return await self._make_request("GET", endpoint="/api/v5/market/candles", params=params)
247
308
 
248
- # topic: Public Data
249
- # sub-topic: REST API
309
+ return await self._make_request(
310
+ "GET",
311
+ endpoint="/api/v5/account/positions-history",
312
+ params=params,
313
+ signed=True,
314
+ )
250
315
 
251
- async def get_funding_rate(self, inst_id: str) -> dict:
252
- """Получение информации о ставке финансирования.
316
+ async def get_account_position_risk(
317
+ self, inst_type: Literal["MARGIN", "SWAP", "FUTURES", "OPTION"] | None = None
318
+ ) -> dict:
319
+ """Получение риска по аккаунту и позициям.
253
320
 
254
- https://www.okx.com/docs-v5/en/#public-data-rest-api-get-funding-rate
321
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-account-and-position-risk
322
+ """
323
+ params = {
324
+ "instType": inst_type,
325
+ }
326
+
327
+ return await self._make_request(
328
+ "GET",
329
+ endpoint="/api/v5/account/account-position-risk",
330
+ params=params,
331
+ signed=True,
332
+ )
333
+
334
+ async def get_account_bills(
335
+ self,
336
+ inst_type: Literal["SPOT", "MARGIN", "SWAP", "FUTURES", "OPTION"] | None = None,
337
+ inst_id: str | None = None,
338
+ ccy: str | None = None,
339
+ mgn_mode: Literal["isolated", "cross"] | None = None,
340
+ ct_type: Literal["linear", "inverse"] | None = None,
341
+ type_: str | None = None,
342
+ sub_type: str | None = None,
343
+ after: str | None = None,
344
+ before: str | None = None,
345
+ begin: int | None = None,
346
+ end: int | None = None,
347
+ limit: int | None = None,
348
+ ) -> dict:
349
+ """Получение выписок за последние 7 дней.
350
+
351
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-bills-details-last-7-days
255
352
  """
256
353
  params = {
354
+ "instType": inst_type,
257
355
  "instId": inst_id,
356
+ "ccy": ccy,
357
+ "mgnMode": mgn_mode,
358
+ "ctType": ct_type,
359
+ "type": type_,
360
+ "subType": sub_type,
361
+ "after": after,
362
+ "before": before,
363
+ "begin": begin,
364
+ "end": end,
365
+ "limit": limit,
258
366
  }
367
+
259
368
  return await self._make_request(
260
- "GET", endpoint="/api/v5/public/funding-rate", params=params
369
+ "GET",
370
+ endpoint="/api/v5/account/bills",
371
+ params=params,
372
+ signed=True,
261
373
  )
262
374
 
263
- async def get_open_interest(
375
+ async def get_account_bills_archive(
264
376
  self,
265
- inst_type: Literal["SWAP", "FUTURES", "OPTION"],
266
- inst_family: str | None = None,
377
+ inst_type: Literal["SPOT", "MARGIN", "SWAP", "FUTURES", "OPTION"] | None = None,
267
378
  inst_id: str | None = None,
379
+ ccy: str | None = None,
380
+ mgn_mode: Literal["isolated", "cross"] | None = None,
381
+ ct_type: Literal["linear", "inverse"] | None = None,
382
+ type_: str | None = None,
383
+ sub_type: str | None = None,
384
+ after: str | None = None,
385
+ before: str | None = None,
386
+ begin: int | None = None,
387
+ end: int | None = None,
388
+ limit: int | None = None,
268
389
  ) -> dict:
269
- """Получение информации по открытому интересу.
390
+ """Получение выписок за последние 3 месяца.
270
391
 
271
- https://www.okx.com/docs-v5/en/#public-data-rest-api-get-open-interest
392
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-bills-details-last-3-months
393
+ """
394
+ params = {
395
+ "instType": inst_type,
396
+ "instId": inst_id,
397
+ "ccy": ccy,
398
+ "mgnMode": mgn_mode,
399
+ "ctType": ct_type,
400
+ "type": type_,
401
+ "subType": sub_type,
402
+ "after": after,
403
+ "before": before,
404
+ "begin": begin,
405
+ "end": end,
406
+ "limit": limit,
407
+ }
408
+
409
+ return await self._make_request(
410
+ "GET",
411
+ endpoint="/api/v5/account/bills-archive",
412
+ params=params,
413
+ signed=True,
414
+ )
415
+
416
+ async def apply_bills_history_archive(
417
+ self, year: str, quarter: Literal["Q1", "Q2", "Q3", "Q4"]
418
+ ) -> dict:
419
+ """Запрос на формирование архива выписок.
420
+
421
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-apply-bills-details-since-2021
422
+ """
423
+ data = {
424
+ "year": year,
425
+ "quarter": quarter,
426
+ }
427
+
428
+ return await self._make_request(
429
+ "POST",
430
+ endpoint="/api/v5/account/bills-history-archive",
431
+ data=data,
432
+ signed=True,
433
+ )
434
+
435
+ async def get_bills_history_archive(
436
+ self, year: str, quarter: Literal["Q1", "Q2", "Q3", "Q4"]
437
+ ) -> dict:
438
+ """Получение ссылки на архив выписок.
439
+
440
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-bills-details-since-2021
441
+ """
442
+ params = {
443
+ "year": year,
444
+ "quarter": quarter,
445
+ }
446
+
447
+ return await self._make_request(
448
+ "GET",
449
+ endpoint="/api/v5/account/bills-history-archive",
450
+ params=params,
451
+ signed=True,
452
+ )
453
+
454
+ async def get_account_config(self) -> dict:
455
+ """Получение конфигурации аккаунта.
456
+
457
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-account-configuration
458
+ """
459
+ return await self._make_request(
460
+ "GET",
461
+ endpoint="/api/v5/account/config",
462
+ signed=True,
463
+ )
464
+
465
+ async def set_position_mode(self, pos_mode: Literal["long_short_mode", "net_mode"]) -> dict:
466
+ """Изменение режима позиций.
467
+
468
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-position-mode
469
+ """
470
+ data = {
471
+ "posMode": pos_mode,
472
+ }
473
+
474
+ return await self._make_request(
475
+ "POST",
476
+ endpoint="/api/v5/account/set-position-mode",
477
+ data=data,
478
+ signed=True,
479
+ )
480
+
481
+ async def set_leverage(
482
+ self,
483
+ lever: str,
484
+ mgn_mode: Literal["isolated", "cross"],
485
+ inst_id: str | None = None,
486
+ ccy: str | None = None,
487
+ pos_side: Literal["long", "short"] | None = None,
488
+ ) -> dict:
489
+ """Установка плеча.
490
+
491
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-leverage
492
+ """
493
+ data = {
494
+ "instId": inst_id,
495
+ "ccy": ccy,
496
+ "lever": lever,
497
+ "mgnMode": mgn_mode,
498
+ "posSide": pos_side,
499
+ }
500
+
501
+ return await self._make_request(
502
+ "POST",
503
+ endpoint="/api/v5/account/set-leverage",
504
+ data=data,
505
+ signed=True,
506
+ )
507
+
508
+ async def get_max_order_size(
509
+ self,
510
+ inst_id: str,
511
+ td_mode: Literal["cross", "isolated", "cash", "spot_isolated"],
512
+ ccy: str | None = None,
513
+ px: str | None = None,
514
+ leverage: str | None = None,
515
+ trade_quote_ccy: str | None = None,
516
+ ) -> dict:
517
+ """Получение максимального размера ордера.
518
+
519
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-maximum-order-quantity
520
+ """
521
+ params = {
522
+ "instId": inst_id,
523
+ "tdMode": td_mode,
524
+ "ccy": ccy,
525
+ "px": px,
526
+ "leverage": leverage,
527
+ "tradeQuoteCcy": trade_quote_ccy,
528
+ }
529
+
530
+ return await self._make_request(
531
+ "GET",
532
+ endpoint="/api/v5/account/max-size",
533
+ params=params,
534
+ signed=True,
535
+ )
536
+
537
+ async def get_max_avail_size(
538
+ self,
539
+ inst_id: str,
540
+ td_mode: Literal["cross", "isolated", "cash", "spot_isolated"],
541
+ ccy: str | None = None,
542
+ reduce_only: bool | None = None,
543
+ px: str | None = None,
544
+ trade_quote_ccy: str | None = None,
545
+ ) -> dict:
546
+ """Получение максимального доступного баланса/эквити.
547
+
548
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-maximum-available-balance-equity
549
+ """
550
+ params = {
551
+ "instId": inst_id,
552
+ "ccy": ccy,
553
+ "tdMode": td_mode,
554
+ "reduceOnly": reduce_only,
555
+ "px": px,
556
+ "tradeQuoteCcy": trade_quote_ccy,
557
+ }
558
+
559
+ return await self._make_request(
560
+ "GET",
561
+ endpoint="/api/v5/account/max-avail-size",
562
+ params=params,
563
+ signed=True,
564
+ )
565
+
566
+ async def adjustment_margin(
567
+ self,
568
+ inst_id: str,
569
+ pos_side: Literal["long", "short", "net"],
570
+ type_: Literal["add", "reduce"],
571
+ amt: str,
572
+ ccy: str | None = None,
573
+ ) -> dict:
574
+ """Изменение маржи изолированной позиции.
575
+
576
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-increase-decrease-margin
577
+ """
578
+ data = {
579
+ "instId": inst_id,
580
+ "posSide": pos_side,
581
+ "type": type_,
582
+ "amt": amt,
583
+ "ccy": ccy,
584
+ }
585
+
586
+ return await self._make_request(
587
+ "POST",
588
+ endpoint="/api/v5/account/position/margin-balance",
589
+ data=data,
590
+ signed=True,
591
+ )
592
+
593
+ async def get_leverage(
594
+ self,
595
+ mgn_mode: Literal["isolated", "cross"],
596
+ inst_id: str | None = None,
597
+ ccy: str | None = None,
598
+ ) -> dict:
599
+ """Получение текущего плеча.
600
+
601
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-leverage
602
+ """
603
+ params = {
604
+ "instId": inst_id,
605
+ "ccy": ccy,
606
+ "mgnMode": mgn_mode,
607
+ }
608
+
609
+ return await self._make_request(
610
+ "GET",
611
+ endpoint="/api/v5/account/leverage-info",
612
+ params=params,
613
+ signed=True,
614
+ )
615
+
616
+ async def get_leverage_estimated_info(
617
+ self,
618
+ inst_type: Literal["MARGIN", "SWAP", "FUTURES"],
619
+ mgn_mode: Literal["isolated", "cross"],
620
+ lever: str,
621
+ inst_id: str | None = None,
622
+ ccy: str | None = None,
623
+ pos_side: Literal["net", "long", "short"] | None = None,
624
+ ) -> dict:
625
+ """Получение оценочных данных по плечу.
626
+
627
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-leverage-estimated-info
628
+ """
629
+ params = {
630
+ "instType": inst_type,
631
+ "mgnMode": mgn_mode,
632
+ "lever": lever,
633
+ "instId": inst_id,
634
+ "ccy": ccy,
635
+ "posSide": pos_side,
636
+ }
637
+
638
+ return await self._make_request(
639
+ "GET",
640
+ endpoint="/api/v5/account/adjust-leverage-info",
641
+ params=params,
642
+ signed=True,
643
+ )
644
+
645
+ async def get_max_loan(
646
+ self,
647
+ mgn_mode: Literal["isolated", "cross"],
648
+ inst_id: str | None = None,
649
+ ccy: str | None = None,
650
+ mgn_ccy: str | None = None,
651
+ trade_quote_ccy: str | None = None,
652
+ ) -> dict:
653
+ """Получение максимального объема заимствования.
654
+
655
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-the-maximum-loan-of-instrument
656
+ """
657
+ params = {
658
+ "mgnMode": mgn_mode,
659
+ "instId": inst_id,
660
+ "ccy": ccy,
661
+ "mgnCcy": mgn_ccy,
662
+ "tradeQuoteCcy": trade_quote_ccy,
663
+ }
664
+
665
+ return await self._make_request(
666
+ "GET",
667
+ endpoint="/api/v5/account/max-loan",
668
+ params=params,
669
+ signed=True,
670
+ )
671
+
672
+ async def get_fee_rates(
673
+ self,
674
+ inst_type: Literal["SPOT", "MARGIN", "SWAP", "FUTURES", "OPTION"],
675
+ inst_id: str | None = None,
676
+ inst_family: str | None = None,
677
+ rule_type: Literal["normal", "pre_market"] | None = None,
678
+ ) -> dict:
679
+ """Получение торговых комиссий.
680
+
681
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-fee-rates
272
682
  """
273
683
  params = {
274
684
  "instType": inst_type,
685
+ "instId": inst_id,
275
686
  "instFamily": inst_family,
687
+ "ruleType": rule_type,
688
+ }
689
+
690
+ return await self._make_request(
691
+ "GET",
692
+ endpoint="/api/v5/account/trade-fee",
693
+ params=params,
694
+ signed=True,
695
+ )
696
+
697
+ async def get_interest_accrued(
698
+ self,
699
+ type_: str | None = None,
700
+ ccy: str | None = None,
701
+ inst_id: str | None = None,
702
+ mgn_mode: Literal["cross", "isolated"] | None = None,
703
+ after: int | None = None,
704
+ before: int | None = None,
705
+ limit: int | None = None,
706
+ ) -> dict:
707
+ """Получение данных по начисленным процентам.
708
+
709
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-interest-accrued-data
710
+ """
711
+ params = {
712
+ "type": type_,
713
+ "ccy": ccy,
276
714
  "instId": inst_id,
715
+ "mgnMode": mgn_mode,
716
+ "after": after,
717
+ "before": before,
718
+ "limit": limit,
277
719
  }
720
+
721
+ return await self._make_request(
722
+ "GET",
723
+ endpoint="/api/v5/account/interest-accrued",
724
+ params=params,
725
+ signed=True,
726
+ )
727
+
728
+ async def get_interest_rate(self, ccy: str | None = None) -> dict:
729
+ """Получение текущих процентных ставок.
730
+
731
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-interest-rate
732
+ """
733
+ params = {
734
+ "ccy": ccy,
735
+ }
736
+
278
737
  return await self._make_request(
279
- "GET", endpoint="/api/v5/public/open-interest", params=params
738
+ "GET",
739
+ endpoint="/api/v5/account/interest-rate",
740
+ params=params,
741
+ signed=True,
742
+ )
743
+
744
+ async def set_fee_type(self, fee_type: Literal["0", "1"]) -> dict:
745
+ """Настройка типа комиссии.
746
+
747
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-fee-type
748
+ """
749
+ data = {
750
+ "feeType": fee_type,
751
+ }
752
+
753
+ return await self._make_request(
754
+ "POST",
755
+ endpoint="/api/v5/account/set-fee-type",
756
+ data=data,
757
+ signed=True,
758
+ )
759
+
760
+ async def set_greeks(self, greeks_type: Literal["PA", "BS"]) -> dict:
761
+ """Настройка формата греков.
762
+
763
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-greeks-pa-bs
764
+ """
765
+ data = {
766
+ "greeksType": greeks_type,
767
+ }
768
+
769
+ return await self._make_request(
770
+ "POST",
771
+ endpoint="/api/v5/account/set-greeks",
772
+ data=data,
773
+ signed=True,
774
+ )
775
+
776
+ async def set_isolated_mode(
777
+ self,
778
+ iso_mode: Literal["auto_transfers_ccy", "automatic"],
779
+ type_: Literal["MARGIN", "CONTRACTS"],
780
+ ) -> dict:
781
+ """Настройка режима изолированной маржи.
782
+
783
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-isolated-margin-trading-settings
784
+ """
785
+ data = {
786
+ "isoMode": iso_mode,
787
+ "type": type_,
788
+ }
789
+
790
+ return await self._make_request(
791
+ "POST",
792
+ endpoint="/api/v5/account/set-isolated-mode",
793
+ data=data,
794
+ signed=True,
795
+ )
796
+
797
+ async def get_max_withdrawal(self, ccy: str | None = None) -> dict:
798
+ """Получение максимальной суммы вывода из трейдингового аккаунта.
799
+
800
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-maximum-withdrawals
801
+ """
802
+ params = {
803
+ "ccy": ccy,
804
+ }
805
+
806
+ return await self._make_request(
807
+ "GET",
808
+ endpoint="/api/v5/account/max-withdrawal",
809
+ params=params,
810
+ signed=True,
811
+ )
812
+
813
+ async def get_risk_state(self) -> dict:
814
+ """Получение статуса рисков аккаунта.
815
+
816
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-account-risk-state
817
+ """
818
+ return await self._make_request(
819
+ "GET",
820
+ endpoint="/api/v5/account/risk-state",
821
+ signed=True,
822
+ )
823
+
824
+ async def get_interest_limits(
825
+ self,
826
+ type_: str | None = None,
827
+ ccy: str | None = None,
828
+ ) -> dict:
829
+ """Получение лимитов и процентов заимствования.
830
+
831
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-borrow-interest-and-limit
832
+ """
833
+ params = {
834
+ "type": type_,
835
+ "ccy": ccy,
836
+ }
837
+
838
+ return await self._make_request(
839
+ "GET",
840
+ endpoint="/api/v5/account/interest-limits",
841
+ params=params,
842
+ signed=True,
843
+ )
844
+
845
+ async def spot_manual_borrow_repay(
846
+ self, ccy: str, side: Literal["borrow", "repay"], amt: str
847
+ ) -> dict:
848
+ """Ручное заимствование или погашение в спотовом режиме.
849
+
850
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-manual-borrow-repay
851
+ """
852
+ data = {
853
+ "ccy": ccy,
854
+ "side": side,
855
+ "amt": amt,
856
+ }
857
+
858
+ return await self._make_request(
859
+ "POST",
860
+ endpoint="/api/v5/account/spot-manual-borrow-repay",
861
+ data=data,
862
+ signed=True,
863
+ )
864
+
865
+ async def set_auto_repay(self, auto_repay: bool) -> dict:
866
+ """Настройка автоматического погашения в спотовом режиме.
867
+
868
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-auto-repay
869
+ """
870
+ data = {
871
+ "autoRepay": auto_repay,
872
+ }
873
+
874
+ return await self._make_request(
875
+ "POST",
876
+ endpoint="/api/v5/account/set-auto-repay",
877
+ data=data,
878
+ signed=True,
879
+ )
880
+
881
+ async def spot_borrow_repay_history(
882
+ self,
883
+ ccy: str | None = None,
884
+ type_: Literal["auto_borrow", "auto_repay", "manual_borrow", "manual_repay"] | None = None,
885
+ after: int | None = None,
886
+ before: int | None = None,
887
+ limit: int | None = None,
888
+ ) -> dict:
889
+ """Получение истории заимствований и погашений в спотовом режиме.
890
+
891
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-borrow-repay-history
892
+ """
893
+ params = {
894
+ "ccy": ccy,
895
+ "type": type_,
896
+ "after": after,
897
+ "before": before,
898
+ "limit": limit,
899
+ }
900
+
901
+ return await self._make_request(
902
+ "GET",
903
+ endpoint="/api/v5/account/spot-borrow-repay-history",
904
+ params=params,
905
+ signed=True,
906
+ )
907
+
908
+ async def position_builder(
909
+ self,
910
+ acct_lv: str | None = None,
911
+ incl_real_pos_and_eq: bool | None = None,
912
+ lever: str | None = None,
913
+ sim_pos: list[dict[str, Any]] | None = None,
914
+ sim_asset: list[dict[str, Any]] | None = None,
915
+ greeks_type: Literal["BS", "PA", "CASH"] | None = None,
916
+ idx_vol: str | None = None,
917
+ ) -> dict:
918
+ """Расчет параметров портфеля с виртуальными позициями.
919
+
920
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-position-builder-new
921
+ """
922
+ data = {
923
+ "acctLv": acct_lv,
924
+ "inclRealPosAndEq": incl_real_pos_and_eq,
925
+ "lever": lever,
926
+ "simPos": sim_pos,
927
+ "simAsset": sim_asset,
928
+ "greeksType": greeks_type,
929
+ "idxVol": idx_vol,
930
+ }
931
+
932
+ return await self._make_request(
933
+ "POST",
934
+ endpoint="/api/v5/account/position-builder",
935
+ data=data,
936
+ signed=True,
937
+ )
938
+
939
+ async def position_builder_graph(
940
+ self,
941
+ type_: Literal["mmr"],
942
+ incl_real_pos_and_eq: bool | None = None,
943
+ sim_pos: list[dict[str, Any]] | None = None,
944
+ sim_asset: list[dict[str, Any]] | None = None,
945
+ greeks_type: Literal["BS", "PA", "CASH"] | None = None,
946
+ mmr_config: dict[str, Any] | None = None,
947
+ ) -> dict:
948
+ """Расчет графика тренда риск-параметров.
949
+
950
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-position-builder-trend-graph
951
+ """
952
+ data = {
953
+ "inclRealPosAndEq": incl_real_pos_and_eq,
954
+ "simPos": sim_pos,
955
+ "simAsset": sim_asset,
956
+ "greeksType": greeks_type,
957
+ "type": type_,
958
+ "mmrConfig": mmr_config,
959
+ }
960
+
961
+ return await self._make_request(
962
+ "POST",
963
+ endpoint="/api/v5/account/position-builder-graph",
964
+ data=data,
965
+ signed=True,
966
+ )
967
+
968
+ async def set_risk_offset_amount(self, ccy: str, cl_spot_in_use_amt: str) -> dict:
969
+ """Установка величины спотового риск-офсета.
970
+
971
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-risk-offset-amount
972
+ """
973
+ data = {
974
+ "ccy": ccy,
975
+ "clSpotInUseAmt": cl_spot_in_use_amt,
976
+ }
977
+
978
+ return await self._make_request(
979
+ "POST",
980
+ endpoint="/api/v5/account/set-riskOffset-amt",
981
+ data=data,
982
+ signed=True,
983
+ )
984
+
985
+ async def get_greeks(self, ccy: str | None = None) -> dict:
986
+ """Получение греков по активам.
987
+
988
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-greeks
989
+ """
990
+ params = {
991
+ "ccy": ccy,
992
+ }
993
+
994
+ return await self._make_request(
995
+ "GET",
996
+ endpoint="/api/v5/account/greeks",
997
+ params=params,
998
+ signed=True,
999
+ )
1000
+
1001
+ async def get_account_position_tiers(
1002
+ self,
1003
+ inst_type: Literal["SWAP", "FUTURES", "OPTION"],
1004
+ inst_family: str,
1005
+ uly: str | None = None,
1006
+ ) -> dict:
1007
+ """Получение лимитов позиций в PM режиме.
1008
+
1009
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-pm-position-limitation
1010
+ """
1011
+ params = {
1012
+ "instType": inst_type,
1013
+ "instFamily": inst_family,
1014
+ "uly": uly,
1015
+ }
1016
+
1017
+ return await self._make_request(
1018
+ "GET",
1019
+ endpoint="/api/v5/account/position-tiers",
1020
+ params=params,
1021
+ signed=True,
1022
+ )
1023
+
1024
+ async def activate_option(self) -> dict:
1025
+ """Активация торговли опционами.
1026
+
1027
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-activate-option
1028
+ """
1029
+ return await self._make_request(
1030
+ "POST",
1031
+ endpoint="/api/v5/account/activate-option",
1032
+ data={},
1033
+ signed=True,
1034
+ )
1035
+
1036
+ async def set_auto_loan(self, auto_loan: bool | None = None) -> dict:
1037
+ """Настройка автоматического заимствования.
1038
+
1039
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-auto-loan
1040
+ """
1041
+ data = {
1042
+ "autoLoan": auto_loan,
1043
+ }
1044
+
1045
+ return await self._make_request(
1046
+ "POST",
1047
+ endpoint="/api/v5/account/set-auto-loan",
1048
+ data=data,
1049
+ signed=True,
1050
+ )
1051
+
1052
+ async def account_level_switch_preset(
1053
+ self, acct_lv: Literal["2", "3", "4"], lever: str | None = None
1054
+ ) -> dict:
1055
+ """Преднастройка смены режима аккаунта.
1056
+
1057
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-preset-account-mode-switch
1058
+ """
1059
+ data = {
1060
+ "acctLv": acct_lv,
1061
+ "lever": lever,
1062
+ }
1063
+
1064
+ return await self._make_request(
1065
+ "POST",
1066
+ endpoint="/api/v5/account/account-level-switch-preset",
1067
+ data=data,
1068
+ signed=True,
1069
+ )
1070
+
1071
+ async def get_account_switch_precheck(self, acct_lv: Literal["1", "2", "3", "4"]) -> dict:
1072
+ """Предварительная проверка смены режима аккаунта.
1073
+
1074
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-precheck-account-mode-switch
1075
+ """
1076
+ params = {
1077
+ "acctLv": acct_lv,
1078
+ }
1079
+
1080
+ return await self._make_request(
1081
+ "GET",
1082
+ endpoint="/api/v5/account/set-account-switch-precheck",
1083
+ params=params,
1084
+ signed=True,
1085
+ )
1086
+
1087
+ async def set_account_level(self, acct_lv: Literal["1", "2", "3", "4"]) -> dict:
1088
+ """Смена режима аккаунта.
1089
+
1090
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-account-mode
1091
+ """
1092
+ data = {
1093
+ "acctLv": acct_lv,
1094
+ }
1095
+
1096
+ return await self._make_request(
1097
+ "POST",
1098
+ endpoint="/api/v5/account/set-account-level",
1099
+ data=data,
1100
+ signed=True,
1101
+ )
1102
+
1103
+ async def set_collateral_assets(
1104
+ self,
1105
+ type_: Literal["all", "custom"],
1106
+ collateral_enabled: bool,
1107
+ ccy_list: list[str] | None = None,
1108
+ ) -> dict:
1109
+ """Настройка списка коллатеральных активов.
1110
+
1111
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-collateral-assets
1112
+ """
1113
+ data = {
1114
+ "type": type_,
1115
+ "collateralEnabled": collateral_enabled,
1116
+ "ccyList": ccy_list,
1117
+ }
1118
+
1119
+ return await self._make_request(
1120
+ "POST",
1121
+ endpoint="/api/v5/account/set-collateral-assets",
1122
+ data=data,
1123
+ signed=True,
1124
+ )
1125
+
1126
+ async def get_collateral_assets(
1127
+ self, ccy: str | None = None, collateral_enabled: bool | None = None
1128
+ ) -> dict:
1129
+ """Получение списка коллатеральных активов.
1130
+
1131
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-collateral-assets
1132
+ """
1133
+ params = {
1134
+ "ccy": ccy,
1135
+ "collateralEnabled": collateral_enabled,
1136
+ }
1137
+
1138
+ return await self._make_request(
1139
+ "GET",
1140
+ endpoint="/api/v5/account/collateral-assets",
1141
+ params=params,
1142
+ signed=True,
1143
+ )
1144
+
1145
+ async def reset_mmp_status(
1146
+ self, inst_family: str, inst_type: Literal["OPTION"] | None = None
1147
+ ) -> dict:
1148
+ """Сброс статуса MMP.
1149
+
1150
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-reset-mmp-status
1151
+ """
1152
+ data = {
1153
+ "instType": inst_type,
1154
+ "instFamily": inst_family,
1155
+ }
1156
+
1157
+ return await self._make_request(
1158
+ "POST",
1159
+ endpoint="/api/v5/account/mmp-reset",
1160
+ data=data,
1161
+ signed=True,
1162
+ )
1163
+
1164
+ async def set_mmp(
1165
+ self,
1166
+ inst_family: str,
1167
+ time_interval: str,
1168
+ frozen_interval: str,
1169
+ qty_limit: str,
1170
+ ) -> dict:
1171
+ """Настройка параметров MMP.
1172
+
1173
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-mmp
1174
+ """
1175
+ data = {
1176
+ "instFamily": inst_family,
1177
+ "timeInterval": time_interval,
1178
+ "frozenInterval": frozen_interval,
1179
+ "qtyLimit": qty_limit,
1180
+ }
1181
+
1182
+ return await self._make_request(
1183
+ "POST",
1184
+ endpoint="/api/v5/account/mmp-config",
1185
+ data=data,
1186
+ signed=True,
1187
+ )
1188
+
1189
+ async def get_mmp_config(self, inst_family: str | None = None) -> dict:
1190
+ """Получение настроек MMP.
1191
+
1192
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-mmp-config
1193
+ """
1194
+ params = {
1195
+ "instFamily": inst_family,
1196
+ }
1197
+
1198
+ return await self._make_request(
1199
+ "GET",
1200
+ endpoint="/api/v5/account/mmp-config",
1201
+ params=params,
1202
+ signed=True,
1203
+ )
1204
+
1205
+ async def move_positions(
1206
+ self,
1207
+ from_acct: str,
1208
+ to_acct: str,
1209
+ legs: list[dict[str, Any]],
1210
+ client_id: str,
1211
+ ) -> dict:
1212
+ """Перемещение позиций между аккаунтами.
1213
+
1214
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-move-positions
1215
+ """
1216
+ data = {
1217
+ "fromAcct": from_acct,
1218
+ "toAcct": to_acct,
1219
+ "legs": legs,
1220
+ "clientId": client_id,
1221
+ }
1222
+
1223
+ return await self._make_request(
1224
+ "POST",
1225
+ endpoint="/api/v5/account/move-positions",
1226
+ data=data,
1227
+ signed=True,
1228
+ )
1229
+
1230
+ async def get_move_positions_history(
1231
+ self,
1232
+ block_td_id: str | None = None,
1233
+ client_id: str | None = None,
1234
+ begin_ts: int | None = None,
1235
+ end_ts: int | None = None,
1236
+ limit: int | None = None,
1237
+ state: Literal["filled", "pending"] | None = None,
1238
+ ) -> dict:
1239
+ """Получение истории перемещения позиций.
1240
+
1241
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-move-positions-history
1242
+ """
1243
+ params = {
1244
+ "blockTdId": block_td_id,
1245
+ "clientId": client_id,
1246
+ "beginTs": begin_ts,
1247
+ "endTs": end_ts,
1248
+ "limit": limit,
1249
+ "state": state,
1250
+ }
1251
+
1252
+ return await self._make_request(
1253
+ "GET",
1254
+ endpoint="/api/v5/account/move-positions-history",
1255
+ params=params,
1256
+ signed=True,
1257
+ )
1258
+
1259
+ async def set_auto_earn(
1260
+ self,
1261
+ ccy: str,
1262
+ action: Literal["turn_on", "turn_off"],
1263
+ earn_type: Literal["0", "1"] | None = None,
1264
+ ) -> dict:
1265
+ """Настройка автоматического Earn.
1266
+
1267
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-auto-earn
1268
+ """
1269
+ data = {
1270
+ "earnType": earn_type,
1271
+ "ccy": ccy,
1272
+ "action": action,
1273
+ }
1274
+
1275
+ return await self._make_request(
1276
+ "POST",
1277
+ endpoint="/api/v5/account/set-auto-earn",
1278
+ data=data,
1279
+ signed=True,
1280
+ )
1281
+
1282
+ async def set_settle_currency(self, settle_ccy: str) -> dict:
1283
+ """Настройка расчетной валюты для USD-маржинальных контрактов.
1284
+
1285
+ https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-settle-currency
1286
+ """
1287
+ data = {
1288
+ "settleCcy": settle_ccy,
1289
+ }
1290
+
1291
+ return await self._make_request(
1292
+ "POST",
1293
+ endpoint="/api/v5/account/set-settle-currency",
1294
+ data=data,
1295
+ signed=True,
1296
+ )
1297
+
1298
+ # topic: Order Book Trading (Trade)
1299
+
1300
+ async def place_order(
1301
+ self,
1302
+ inst_id: str,
1303
+ td_mode: Literal["cross", "isolated", "cash", "spot_isolated"],
1304
+ side: Literal["buy", "sell"],
1305
+ ord_type: Literal[
1306
+ "market",
1307
+ "limit",
1308
+ "post_only",
1309
+ "fok",
1310
+ "ioc",
1311
+ "optimal_limit_ioc",
1312
+ "mmp",
1313
+ "mmp_and_post_only",
1314
+ "op_fok",
1315
+ ],
1316
+ sz: str,
1317
+ ccy: str | None = None,
1318
+ cl_ord_id: str | None = None,
1319
+ tag: str | None = None,
1320
+ pos_side: Literal["net", "long", "short"] | None = None,
1321
+ px: str | None = None,
1322
+ px_usd: str | None = None,
1323
+ px_vol: str | None = None,
1324
+ reduce_only: bool | None = None,
1325
+ tgt_ccy: Literal["base_ccy", "quote_ccy"] | None = None,
1326
+ ban_amend: bool | None = None,
1327
+ px_amend_type: Literal["0", "1"] | None = None,
1328
+ trade_quote_ccy: str | None = None,
1329
+ stp_mode: Literal["cancel_maker", "cancel_taker", "cancel_both"] | None = None,
1330
+ quick_mgn_type: str | None = None,
1331
+ attach_algo_orders: list[dict[str, Any]] | None = None,
1332
+ extra_params: dict[str, Any] | None = None,
1333
+ ) -> dict:
1334
+ """Создание ордера.
1335
+
1336
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
1337
+ """
1338
+ data: dict[str, Any] = {
1339
+ "instId": inst_id,
1340
+ "tdMode": td_mode,
1341
+ "side": side,
1342
+ "ordType": ord_type,
1343
+ "sz": sz,
1344
+ "ccy": ccy,
1345
+ "clOrdId": cl_ord_id,
1346
+ "tag": tag,
1347
+ "posSide": pos_side,
1348
+ "px": px,
1349
+ "pxUsd": px_usd,
1350
+ "pxVol": px_vol,
1351
+ "reduceOnly": reduce_only,
1352
+ "tgtCcy": tgt_ccy,
1353
+ "banAmend": ban_amend,
1354
+ "pxAmendType": px_amend_type,
1355
+ "tradeQuoteCcy": trade_quote_ccy,
1356
+ "stpMode": stp_mode,
1357
+ "quickMgnType": quick_mgn_type,
1358
+ }
1359
+ if attach_algo_orders is not None:
1360
+ data["attachAlgoOrds"] = [filter_params(order) for order in attach_algo_orders]
1361
+ if extra_params:
1362
+ data.update(extra_params)
1363
+
1364
+ return await self._make_request(
1365
+ "POST",
1366
+ endpoint="/api/v5/trade/order",
1367
+ data=filter_params(data),
1368
+ signed=True,
1369
+ )
1370
+
1371
+ async def place_multiple_orders(self, orders: list[dict[str, Any]]) -> dict:
1372
+ """Создание ордеров пакетно.
1373
+
1374
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-multiple-orders
1375
+ """
1376
+ data = [filter_params(order) for order in orders]
1377
+
1378
+ return await self._make_request(
1379
+ "POST",
1380
+ endpoint="/api/v5/trade/batch-orders",
1381
+ data=data, # type: ignore
1382
+ signed=True,
1383
+ )
1384
+
1385
+ async def cancel_order(
1386
+ self,
1387
+ inst_id: str,
1388
+ ord_id: str | None = None,
1389
+ cl_ord_id: str | None = None,
1390
+ ) -> dict:
1391
+ """Отмена ордера.
1392
+
1393
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-cancel-order
1394
+ """
1395
+ if not ord_id and not cl_ord_id:
1396
+ raise ValueError("Either ord_id or cl_ord_id must be provided")
1397
+
1398
+ data = filter_params(
1399
+ {
1400
+ "instId": inst_id,
1401
+ "ordId": ord_id,
1402
+ "clOrdId": cl_ord_id,
1403
+ }
1404
+ )
1405
+
1406
+ return await self._make_request(
1407
+ "POST",
1408
+ endpoint="/api/v5/trade/cancel-order",
1409
+ data=data,
1410
+ signed=True,
1411
+ )
1412
+
1413
+ async def cancel_multiple_orders(self, orders: list[dict[str, Any]]) -> dict:
1414
+ """Отмена ордеров пакетно.
1415
+
1416
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-cancel-multiple-orders
1417
+ """
1418
+ data = [filter_params(order) for order in orders]
1419
+
1420
+ return await self._make_request(
1421
+ "POST",
1422
+ endpoint="/api/v5/trade/cancel-batch-orders",
1423
+ data=data, # type: ignore
1424
+ signed=True,
1425
+ )
1426
+
1427
+ async def amend_order(
1428
+ self,
1429
+ inst_id: str,
1430
+ ord_id: str | None = None,
1431
+ cl_ord_id: str | None = None,
1432
+ *,
1433
+ new_sz: str | None = None,
1434
+ new_px: str | None = None,
1435
+ new_px_usd: str | None = None,
1436
+ new_px_vol: str | None = None,
1437
+ cxl_on_fail: bool | None = None,
1438
+ req_id: str | None = None,
1439
+ px_amend_type: Literal["0", "1"] | None = None,
1440
+ attach_algo_orders: list[dict[str, Any]] | None = None,
1441
+ extra_params: dict[str, Any] | None = None,
1442
+ ) -> dict:
1443
+ """Изменение параметров ордера.
1444
+
1445
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-amend-order
1446
+ """
1447
+ if not ord_id and not cl_ord_id:
1448
+ raise ValueError("Either ord_id or cl_ord_id must be provided")
1449
+
1450
+ data: dict[str, Any] = {
1451
+ "instId": inst_id,
1452
+ "ordId": ord_id,
1453
+ "clOrdId": cl_ord_id,
1454
+ "newSz": new_sz,
1455
+ "newPx": new_px,
1456
+ "newPxUsd": new_px_usd,
1457
+ "newPxVol": new_px_vol,
1458
+ "cxlOnFail": cxl_on_fail,
1459
+ "reqId": req_id,
1460
+ "pxAmendType": px_amend_type,
1461
+ }
1462
+ if attach_algo_orders is not None:
1463
+ data["attachAlgoOrds"] = [filter_params(order) for order in attach_algo_orders]
1464
+ if extra_params:
1465
+ data.update(extra_params)
1466
+
1467
+ return await self._make_request(
1468
+ "POST",
1469
+ endpoint="/api/v5/trade/amend-order",
1470
+ data=filter_params(data),
1471
+ signed=True,
1472
+ )
1473
+
1474
+ async def amend_multiple_orders(self, orders: list[dict[str, Any]]) -> dict:
1475
+ """Изменение параметров ордеров пакетно.
1476
+
1477
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-amend-multiple-orders
1478
+ """
1479
+ data = [filter_params(order) for order in orders]
1480
+
1481
+ return await self._make_request(
1482
+ "POST",
1483
+ endpoint="/api/v5/trade/amend-batch-orders",
1484
+ data=data, # type: ignore
1485
+ signed=True,
1486
+ )
1487
+
1488
+ async def close_positions(
1489
+ self,
1490
+ inst_id: str,
1491
+ mgn_mode: Literal["cross", "isolated"],
1492
+ pos_side: Literal["net", "long", "short"] | None = None,
1493
+ ccy: str | None = None,
1494
+ auto_cxl: bool | None = None,
1495
+ cl_ord_id: str | None = None,
1496
+ tag: str | None = None,
1497
+ extra_params: dict[str, Any] | None = None,
1498
+ ) -> dict:
1499
+ """Закрытие позиции рыночным ордером.
1500
+
1501
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-close-positions
1502
+ """
1503
+ data: dict[str, Any] = {
1504
+ "instId": inst_id,
1505
+ "mgnMode": mgn_mode,
1506
+ "posSide": pos_side,
1507
+ "ccy": ccy,
1508
+ "autoCxl": auto_cxl,
1509
+ "clOrdId": cl_ord_id,
1510
+ "tag": tag,
1511
+ }
1512
+ if extra_params:
1513
+ data.update(extra_params)
1514
+
1515
+ return await self._make_request(
1516
+ "POST",
1517
+ endpoint="/api/v5/trade/close-position",
1518
+ data=filter_params(data),
1519
+ signed=True,
1520
+ )
1521
+
1522
+ async def get_order(
1523
+ self,
1524
+ inst_id: str,
1525
+ ord_id: str | None = None,
1526
+ cl_ord_id: str | None = None,
1527
+ ) -> dict:
1528
+ """Получение информации об ордере.
1529
+
1530
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-details
1531
+ """
1532
+ if not ord_id and not cl_ord_id:
1533
+ raise ValueError("Either ord_id or cl_ord_id must be provided")
1534
+
1535
+ params = filter_params(
1536
+ {
1537
+ "instId": inst_id,
1538
+ "ordId": ord_id,
1539
+ "clOrdId": cl_ord_id,
1540
+ }
1541
+ )
1542
+
1543
+ return await self._make_request(
1544
+ "GET",
1545
+ endpoint="/api/v5/trade/order",
1546
+ params=params,
1547
+ signed=True,
1548
+ )
1549
+
1550
+ async def get_order_list(
1551
+ self,
1552
+ inst_type: str | None = None,
1553
+ inst_family: str | None = None,
1554
+ inst_id: str | None = None,
1555
+ ord_type: str | None = None,
1556
+ state: Literal["live", "partially_filled"] | None = None,
1557
+ after: str | None = None,
1558
+ before: str | None = None,
1559
+ limit: int | None = None,
1560
+ ) -> dict:
1561
+ """Получение списка активных ордеров.
1562
+
1563
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-list
1564
+ """
1565
+ params = filter_params(
1566
+ {
1567
+ "instType": inst_type,
1568
+ "instFamily": inst_family,
1569
+ "instId": inst_id,
1570
+ "ordType": ord_type,
1571
+ "state": state,
1572
+ "after": after,
1573
+ "before": before,
1574
+ "limit": limit,
1575
+ }
1576
+ )
1577
+
1578
+ return await self._make_request(
1579
+ "GET",
1580
+ endpoint="/api/v5/trade/orders-pending",
1581
+ params=params,
1582
+ signed=True,
1583
+ )
1584
+
1585
+ async def get_orders_history(
1586
+ self,
1587
+ inst_type: str,
1588
+ inst_family: str | None = None,
1589
+ inst_id: str | None = None,
1590
+ ord_type: str | None = None,
1591
+ state: str | None = None,
1592
+ category: str | None = None,
1593
+ after: str | None = None,
1594
+ before: str | None = None,
1595
+ begin: int | None = None,
1596
+ end: int | None = None,
1597
+ limit: int | None = None,
1598
+ ) -> dict:
1599
+ """Получение истории ордеров за 7 дней.
1600
+
1601
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-history-last-7-days
1602
+ """
1603
+ params = filter_params(
1604
+ {
1605
+ "instType": inst_type,
1606
+ "instFamily": inst_family,
1607
+ "instId": inst_id,
1608
+ "ordType": ord_type,
1609
+ "state": state,
1610
+ "category": category,
1611
+ "after": after,
1612
+ "before": before,
1613
+ "begin": begin,
1614
+ "end": end,
1615
+ "limit": limit,
1616
+ }
1617
+ )
1618
+
1619
+ return await self._make_request(
1620
+ "GET",
1621
+ endpoint="/api/v5/trade/orders-history",
1622
+ params=params,
1623
+ signed=True,
1624
+ )
1625
+
1626
+ async def get_orders_history_archive(
1627
+ self,
1628
+ inst_type: str,
1629
+ inst_family: str | None = None,
1630
+ inst_id: str | None = None,
1631
+ ord_type: str | None = None,
1632
+ state: str | None = None,
1633
+ category: str | None = None,
1634
+ after: str | None = None,
1635
+ before: str | None = None,
1636
+ begin: int | None = None,
1637
+ end: int | None = None,
1638
+ limit: int | None = None,
1639
+ ) -> dict:
1640
+ """Получение истории ордеров за 3 месяца.
1641
+
1642
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-history-last-3-months
1643
+ """
1644
+ params = filter_params(
1645
+ {
1646
+ "instType": inst_type,
1647
+ "instFamily": inst_family,
1648
+ "instId": inst_id,
1649
+ "ordType": ord_type,
1650
+ "state": state,
1651
+ "category": category,
1652
+ "after": after,
1653
+ "before": before,
1654
+ "begin": begin,
1655
+ "end": end,
1656
+ "limit": limit,
1657
+ }
1658
+ )
1659
+
1660
+ return await self._make_request(
1661
+ "GET",
1662
+ endpoint="/api/v5/trade/orders-history-archive",
1663
+ params=params,
1664
+ signed=True,
1665
+ )
1666
+
1667
+ async def get_fills(
1668
+ self,
1669
+ inst_type: str | None = None,
1670
+ inst_family: str | None = None,
1671
+ inst_id: str | None = None,
1672
+ ord_id: str | None = None,
1673
+ sub_type: str | None = None,
1674
+ after: str | None = None,
1675
+ before: str | None = None,
1676
+ begin: int | None = None,
1677
+ end: int | None = None,
1678
+ limit: int | None = None,
1679
+ ) -> dict:
1680
+ """Получение сделок за 3 дня.
1681
+
1682
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-transaction-details-last-3-days
1683
+ """
1684
+ params = filter_params(
1685
+ {
1686
+ "instType": inst_type,
1687
+ "instFamily": inst_family,
1688
+ "instId": inst_id,
1689
+ "ordId": ord_id,
1690
+ "subType": sub_type,
1691
+ "after": after,
1692
+ "before": before,
1693
+ "begin": begin,
1694
+ "end": end,
1695
+ "limit": limit,
1696
+ }
1697
+ )
1698
+
1699
+ return await self._make_request(
1700
+ "GET",
1701
+ endpoint="/api/v5/trade/fills",
1702
+ params=params,
1703
+ signed=True,
1704
+ )
1705
+
1706
+ async def get_fills_history(
1707
+ self,
1708
+ inst_type: str,
1709
+ inst_family: str | None = None,
1710
+ inst_id: str | None = None,
1711
+ ord_id: str | None = None,
1712
+ sub_type: str | None = None,
1713
+ after: str | None = None,
1714
+ before: str | None = None,
1715
+ begin: int | None = None,
1716
+ end: int | None = None,
1717
+ limit: int | None = None,
1718
+ ) -> dict:
1719
+ """Получение сделок за 3 месяца.
1720
+
1721
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-transaction-details-last-3-months
1722
+ """
1723
+ params = filter_params(
1724
+ {
1725
+ "instType": inst_type,
1726
+ "instFamily": inst_family,
1727
+ "instId": inst_id,
1728
+ "ordId": ord_id,
1729
+ "subType": sub_type,
1730
+ "after": after,
1731
+ "before": before,
1732
+ "begin": begin,
1733
+ "end": end,
1734
+ "limit": limit,
1735
+ }
1736
+ )
1737
+
1738
+ return await self._make_request(
1739
+ "GET",
1740
+ endpoint="/api/v5/trade/fills-history",
1741
+ params=params,
1742
+ signed=True,
1743
+ )
1744
+
1745
+ async def get_easy_convert_currency_list(self, source: Literal["1", "2"] | None = None) -> dict:
1746
+ """Получение списка валют для Easy Convert.
1747
+
1748
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-easy-convert-currency-list
1749
+ """
1750
+ params = filter_params({"source": source})
1751
+
1752
+ return await self._make_request(
1753
+ "GET",
1754
+ endpoint="/api/v5/trade/easy-convert-currency-list",
1755
+ params=params,
1756
+ signed=True,
1757
+ )
1758
+
1759
+ async def easy_convert(
1760
+ self,
1761
+ from_ccy: list[str],
1762
+ to_ccy: str,
1763
+ source: Literal["1", "2"] | None = None,
1764
+ ) -> dict:
1765
+ """Конвертация мелких остатков через Easy Convert.
1766
+
1767
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-easy-convert
1768
+ """
1769
+ data = filter_params(
1770
+ {
1771
+ "fromCcy": from_ccy,
1772
+ "toCcy": to_ccy,
1773
+ "source": source,
1774
+ }
1775
+ )
1776
+
1777
+ return await self._make_request(
1778
+ "POST",
1779
+ endpoint="/api/v5/trade/easy-convert",
1780
+ data=data,
1781
+ signed=True,
1782
+ )
1783
+
1784
+ async def get_easy_convert_history(
1785
+ self,
1786
+ after: str | None = None,
1787
+ before: str | None = None,
1788
+ limit: int | None = None,
1789
+ ) -> dict:
1790
+ """Получение истории Easy Convert.
1791
+
1792
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-easy-convert-history
1793
+ """
1794
+ params = filter_params(
1795
+ {
1796
+ "after": after,
1797
+ "before": before,
1798
+ "limit": limit,
1799
+ }
1800
+ )
1801
+
1802
+ return await self._make_request(
1803
+ "GET",
1804
+ endpoint="/api/v5/trade/easy-convert-history",
1805
+ params=params,
1806
+ signed=True,
1807
+ )
1808
+
1809
+ async def get_one_click_repay_currency_list(
1810
+ self,
1811
+ debt_type: Literal["cross", "isolated"] | None = None,
1812
+ ) -> dict:
1813
+ """Получение списка валют для One-click Repay.
1814
+
1815
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-one-click-repay-currency-list
1816
+ """
1817
+ params = filter_params({"debtType": debt_type})
1818
+
1819
+ return await self._make_request(
1820
+ "GET",
1821
+ endpoint="/api/v5/trade/one-click-repay-currency-list",
1822
+ params=params,
1823
+ signed=True,
1824
+ )
1825
+
1826
+ async def trade_one_click_repay(
1827
+ self,
1828
+ debt_ccy: list[str],
1829
+ repay_ccy: str,
1830
+ ) -> dict:
1831
+ """Совершение One-click Repay.
1832
+
1833
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-trade-one-click-repay
1834
+ """
1835
+ data = filter_params({"debtCcy": debt_ccy, "repayCcy": repay_ccy})
1836
+
1837
+ return await self._make_request(
1838
+ "POST",
1839
+ endpoint="/api/v5/trade/one-click-repay",
1840
+ data=data,
1841
+ signed=True,
1842
+ )
1843
+
1844
+ async def get_one_click_repay_history(
1845
+ self,
1846
+ after: str | None = None,
1847
+ before: str | None = None,
1848
+ limit: int | None = None,
1849
+ ) -> dict:
1850
+ """Получение истории One-click Repay.
1851
+
1852
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-one-click-repay-history
1853
+ """
1854
+ params = filter_params(
1855
+ {
1856
+ "after": after,
1857
+ "before": before,
1858
+ "limit": limit,
1859
+ }
1860
+ )
1861
+
1862
+ return await self._make_request(
1863
+ "GET",
1864
+ endpoint="/api/v5/trade/one-click-repay-history",
1865
+ params=params,
1866
+ signed=True,
1867
+ )
1868
+
1869
+ async def get_one_click_repay_currency_list_v2(self) -> dict:
1870
+ """Получение списка валют для One-click Repay (v2).
1871
+
1872
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-one-click-repay-currency-list-new
1873
+ """
1874
+ return await self._make_request(
1875
+ "GET",
1876
+ endpoint="/api/v5/trade/one-click-repay-currency-list-v2",
1877
+ signed=True,
1878
+ )
1879
+
1880
+ async def trade_one_click_repay_v2(
1881
+ self,
1882
+ debt_ccy: str,
1883
+ repay_ccy_list: list[str],
1884
+ ) -> dict:
1885
+ """Совершение One-click Repay (v2).
1886
+
1887
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-trade-one-click-repay-new
1888
+ """
1889
+ data = filter_params({"debtCcy": debt_ccy, "repayCcyList": repay_ccy_list})
1890
+
1891
+ return await self._make_request(
1892
+ "POST",
1893
+ endpoint="/api/v5/trade/one-click-repay-v2",
1894
+ data=data,
1895
+ signed=True,
1896
+ )
1897
+
1898
+ async def get_one_click_repay_history_v2(
1899
+ self,
1900
+ after: str | None = None,
1901
+ before: str | None = None,
1902
+ limit: int | None = None,
1903
+ ) -> dict:
1904
+ """Получение истории One-click Repay (v2).
1905
+
1906
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-one-click-repay-history-new
1907
+ """
1908
+ params = filter_params(
1909
+ {
1910
+ "after": after,
1911
+ "before": before,
1912
+ "limit": limit,
1913
+ }
1914
+ )
1915
+
1916
+ return await self._make_request(
1917
+ "GET",
1918
+ endpoint="/api/v5/trade/one-click-repay-history-v2",
1919
+ params=params,
1920
+ signed=True,
1921
+ )
1922
+
1923
+ async def mass_cancel_orders(
1924
+ self,
1925
+ inst_type: Literal["OPTION"],
1926
+ inst_family: str,
1927
+ lock_interval: str | None = None,
1928
+ ) -> dict:
1929
+ """Массовое снятие MMP-ордеров.
1930
+
1931
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-mass-cancel-order
1932
+ """
1933
+ data = filter_params(
1934
+ {
1935
+ "instType": inst_type,
1936
+ "instFamily": inst_family,
1937
+ "lockInterval": lock_interval,
1938
+ }
1939
+ )
1940
+
1941
+ return await self._make_request(
1942
+ "POST",
1943
+ endpoint="/api/v5/trade/mass-cancel",
1944
+ data=data,
1945
+ signed=True,
1946
+ )
1947
+
1948
+ async def cancel_all_after(
1949
+ self,
1950
+ time_out: str,
1951
+ tag: str | None = None,
1952
+ ) -> dict:
1953
+ """Установка Cancel All After.
1954
+
1955
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-cancel-all-after
1956
+ """
1957
+ data = filter_params({"timeOut": time_out, "tag": tag})
1958
+
1959
+ return await self._make_request(
1960
+ "POST",
1961
+ endpoint="/api/v5/trade/cancel-all-after",
1962
+ data=data,
1963
+ signed=True,
1964
+ )
1965
+
1966
+ async def get_account_rate_limit(self) -> dict:
1967
+ """Получение информации о лимитах запросов аккаунта.
1968
+
1969
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-account-rate-limit
1970
+ """
1971
+ return await self._make_request(
1972
+ "GET",
1973
+ endpoint="/api/v5/trade/account-rate-limit",
1974
+ signed=True,
1975
+ )
1976
+
1977
+ async def order_precheck(
1978
+ self,
1979
+ inst_id: str,
1980
+ td_mode: Literal["cross", "isolated", "cash", "spot_isolated"],
1981
+ side: Literal["buy", "sell"],
1982
+ ord_type: Literal[
1983
+ "market",
1984
+ "limit",
1985
+ "post_only",
1986
+ "fok",
1987
+ "ioc",
1988
+ "optimal_limit_ioc",
1989
+ ],
1990
+ sz: str,
1991
+ pos_side: Literal["net", "long", "short"] | None = None,
1992
+ px: str | None = None,
1993
+ reduce_only: bool | None = None,
1994
+ tgt_ccy: Literal["base_ccy", "quote_ccy"] | None = None,
1995
+ attach_algo_orders: list[dict[str, Any]] | None = None,
1996
+ extra_params: dict[str, Any] | None = None,
1997
+ ) -> dict:
1998
+ """Превентивная проверка перед размещением ордера.
1999
+
2000
+ https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-order-precheck
2001
+ """
2002
+ data: dict[str, Any] = {
2003
+ "instId": inst_id,
2004
+ "tdMode": td_mode,
2005
+ "side": side,
2006
+ "ordType": ord_type,
2007
+ "sz": sz,
2008
+ "posSide": pos_side,
2009
+ "px": px,
2010
+ "reduceOnly": reduce_only,
2011
+ "tgtCcy": tgt_ccy,
2012
+ }
2013
+ if attach_algo_orders is not None:
2014
+ data["attachAlgoOrds"] = [filter_params(order) for order in attach_algo_orders]
2015
+ if extra_params:
2016
+ data.update(extra_params)
2017
+
2018
+ return await self._make_request(
2019
+ "POST",
2020
+ endpoint="/api/v5/trade/order-precheck",
2021
+ data=filter_params(data),
2022
+ signed=True,
2023
+ )
2024
+
2025
+ # topic: Order Book Trading (Market Data)
2026
+
2027
+ async def get_tickers(
2028
+ self,
2029
+ inst_type: Literal["SPOT", "SWAP", "FUTURES", "OPTION"],
2030
+ inst_family: str | None = None,
2031
+ ) -> dict:
2032
+ """Получение списка тикеров с основными метриками.
2033
+
2034
+ https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-tickers
2035
+ """
2036
+ params = {
2037
+ "instType": inst_type,
2038
+ "instFamily": inst_family,
2039
+ }
2040
+
2041
+ return await self._make_request(
2042
+ "GET",
2043
+ endpoint="/api/v5/market/tickers",
2044
+ params=params,
2045
+ )
2046
+
2047
+ async def get_ticker(self, inst_id: str) -> dict:
2048
+ """Получение тикера инструмента с данными за 24 часа.
2049
+
2050
+ https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-ticker
2051
+ """
2052
+ params = {
2053
+ "instId": inst_id,
2054
+ }
2055
+
2056
+ return await self._make_request(
2057
+ "GET",
2058
+ endpoint="/api/v5/market/ticker",
2059
+ params=params,
2060
+ )
2061
+
2062
+ async def get_order_book(self, inst_id: str, sz: int | None = None) -> dict:
2063
+ """Получение книги ордеров с обновлением каждые 50 мс.
2064
+
2065
+ https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-order-book
2066
+ """
2067
+ params = {
2068
+ "instId": inst_id,
2069
+ "sz": sz,
2070
+ }
2071
+
2072
+ return await self._make_request(
2073
+ "GET",
2074
+ endpoint="/api/v5/market/books",
2075
+ params=params,
2076
+ )
2077
+
2078
+ async def get_full_order_book(self, inst_id: str, sz: int | None = None) -> dict:
2079
+ """Получение полной книги ордеров с глубиной до 5000 уровней.
2080
+
2081
+ https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-full-order-book
2082
+ """
2083
+ params = {
2084
+ "instId": inst_id,
2085
+ "sz": sz,
2086
+ }
2087
+
2088
+ return await self._make_request(
2089
+ "GET",
2090
+ endpoint="/api/v5/market/books-full",
2091
+ params=params,
2092
+ )
2093
+
2094
+ async def get_candlesticks(
2095
+ self,
2096
+ inst_id: str,
2097
+ bar: str | None = None,
2098
+ after: int | None = None,
2099
+ before: int | None = None,
2100
+ limit: int | None = None,
2101
+ ) -> dict:
2102
+ """Получение списка свечей с максимальной глубиной в 1440 записей.
2103
+
2104
+ https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-candlesticks
2105
+ """
2106
+ params = {
2107
+ "instId": inst_id,
2108
+ "bar": bar,
2109
+ "after": after,
2110
+ "before": before,
2111
+ "limit": limit,
2112
+ }
2113
+
2114
+ return await self._make_request(
2115
+ "GET",
2116
+ endpoint="/api/v5/market/candles",
2117
+ params=params,
2118
+ )
2119
+
2120
+ async def get_candlesticks_history(
2121
+ self,
2122
+ inst_id: str,
2123
+ after: int | None = None,
2124
+ before: int | None = None,
2125
+ bar: str | None = None,
2126
+ limit: int | None = None,
2127
+ ) -> dict:
2128
+ """Получение исторических свечей за прошлые периоды.
2129
+
2130
+ https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-candlesticks-history
2131
+ """
2132
+ params = {
2133
+ "instId": inst_id,
2134
+ "after": after,
2135
+ "before": before,
2136
+ "bar": bar,
2137
+ "limit": limit,
2138
+ }
2139
+
2140
+ return await self._make_request(
2141
+ "GET",
2142
+ endpoint="/api/v5/market/history-candles",
2143
+ params=params,
2144
+ )
2145
+
2146
+ async def get_trades(self, inst_id: str, limit: int | None = None) -> dict:
2147
+ """Получение последних сделок по инструменту.
2148
+
2149
+ https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-trades
2150
+ """
2151
+ params = {
2152
+ "instId": inst_id,
2153
+ "limit": limit,
2154
+ }
2155
+
2156
+ return await self._make_request(
2157
+ "GET",
2158
+ endpoint="/api/v5/market/trades",
2159
+ params=params,
2160
+ )
2161
+
2162
+ async def get_trades_history(
2163
+ self,
2164
+ inst_id: str,
2165
+ type_: Literal["1", "2"] | None = None,
2166
+ after: str | None = None,
2167
+ before: str | None = None,
2168
+ limit: int | None = None,
2169
+ ) -> dict:
2170
+ """Получение истории сделок с пагинацией за последние три месяца.
2171
+
2172
+ https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-trades-history
2173
+ """
2174
+ params = {
2175
+ "instId": inst_id,
2176
+ "type": type_,
2177
+ "after": after,
2178
+ "before": before,
2179
+ "limit": limit,
2180
+ }
2181
+
2182
+ return await self._make_request(
2183
+ "GET",
2184
+ endpoint="/api/v5/market/history-trades",
2185
+ params=params,
2186
+ )
2187
+
2188
+ async def get_option_trades_by_family(self, inst_family: str) -> dict:
2189
+ """Получение сделок по всем опционам в рамках семьи инструментов.
2190
+
2191
+ https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-option-trades-by-instrument-family
2192
+ """
2193
+ params = {
2194
+ "instFamily": inst_family,
2195
+ }
2196
+
2197
+ return await self._make_request(
2198
+ "GET",
2199
+ endpoint="/api/v5/market/option/instrument-family-trades",
2200
+ params=params,
2201
+ )
2202
+
2203
+ async def get_option_trades(
2204
+ self,
2205
+ inst_id: str | None = None,
2206
+ inst_family: str | None = None,
2207
+ opt_type: Literal["C", "P"] | None = None,
2208
+ ) -> dict:
2209
+ """Получение сделок по выбранным опционам.
2210
+
2211
+ https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-option-trades
2212
+ """
2213
+ params = {
2214
+ "instId": inst_id,
2215
+ "instFamily": inst_family,
2216
+ "optType": opt_type,
2217
+ }
2218
+
2219
+ return await self._make_request(
2220
+ "GET",
2221
+ endpoint="/api/v5/public/option-trades",
2222
+ params=params,
2223
+ )
2224
+
2225
+ async def get_24h_total_volume(self) -> dict:
2226
+ """Получение совокупного 24-часового объема торгов по платформе.
2227
+
2228
+ https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-24h-total-volume
2229
+ """
2230
+ return await self._make_request(
2231
+ "GET",
2232
+ endpoint="/api/v5/market/platform-24-volume",
2233
+ )
2234
+
2235
+ async def get_call_auction_details(self, inst_id: str) -> dict:
2236
+ """Получение данных по предторговому аукциону инструмента.
2237
+
2238
+ https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-call-auction-details
2239
+ """
2240
+ params = {
2241
+ "instId": inst_id,
2242
+ }
2243
+
2244
+ return await self._make_request(
2245
+ "GET",
2246
+ endpoint="/api/v5/market/call-auction-details",
2247
+ params=params,
2248
+ )
2249
+
2250
+ # topic: Public Data
2251
+
2252
+ async def get_instruments(
2253
+ self,
2254
+ inst_type: Literal["SPOT", "MARGIN", "SWAP", "FUTURES", "OPTION"],
2255
+ inst_family: str | None = None,
2256
+ inst_id: str | None = None,
2257
+ ) -> dict:
2258
+ """Получение списка доступных публичных инструментов.
2259
+
2260
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-instruments
2261
+ """
2262
+ params = {
2263
+ "instType": inst_type,
2264
+ "instFamily": inst_family,
2265
+ "instId": inst_id,
2266
+ }
2267
+
2268
+ return await self._make_request(
2269
+ "GET",
2270
+ endpoint="/api/v5/public/instruments",
2271
+ params=params,
2272
+ )
2273
+
2274
+ async def get_estimated_delivery_price(self, inst_id: str) -> dict:
2275
+ """Получение оценочной цены поставки или исполнения опциона.
2276
+
2277
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-estimated-delivery-exercise-price
2278
+ """
2279
+ params = {
2280
+ "instId": inst_id,
2281
+ }
2282
+
2283
+ return await self._make_request(
2284
+ "GET",
2285
+ endpoint="/api/v5/public/estimated-price",
2286
+ params=params,
2287
+ )
2288
+
2289
+ async def get_delivery_exercise_history(
2290
+ self,
2291
+ inst_type: Literal["FUTURES", "OPTION"],
2292
+ inst_family: str,
2293
+ after: int | None = None,
2294
+ before: int | None = None,
2295
+ limit: int | None = None,
2296
+ ) -> dict:
2297
+ """Получение истории поставок и исполнений за последние три месяца.
2298
+
2299
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-delivery-exercise-history
2300
+ """
2301
+ params = {
2302
+ "instType": inst_type,
2303
+ "instFamily": inst_family,
2304
+ "after": after,
2305
+ "before": before,
2306
+ "limit": limit,
2307
+ }
2308
+
2309
+ return await self._make_request(
2310
+ "GET",
2311
+ endpoint="/api/v5/public/delivery-exercise-history",
2312
+ params=params,
2313
+ )
2314
+
2315
+ async def get_estimated_settlement_info(self, inst_id: str) -> dict:
2316
+ """Получение оценочной цены ближайшего расчета по фьючерсу.
2317
+
2318
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-estimated-future-settlement-price
2319
+ """
2320
+ params = {
2321
+ "instId": inst_id,
2322
+ }
2323
+
2324
+ return await self._make_request(
2325
+ "GET",
2326
+ endpoint="/api/v5/public/estimated-settlement-info",
2327
+ params=params,
2328
+ )
2329
+
2330
+ async def get_futures_settlement_history(
2331
+ self,
2332
+ inst_family: str,
2333
+ after: int | None = None,
2334
+ before: int | None = None,
2335
+ limit: int | None = None,
2336
+ ) -> dict:
2337
+ """Получение истории расчетов фьючерсов за последние три месяца.
2338
+
2339
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-futures-settlement-history
2340
+ """
2341
+ params = {
2342
+ "instFamily": inst_family,
2343
+ "after": after,
2344
+ "before": before,
2345
+ "limit": limit,
2346
+ }
2347
+
2348
+ return await self._make_request(
2349
+ "GET",
2350
+ endpoint="/api/v5/public/settlement-history",
2351
+ params=params,
2352
+ )
2353
+
2354
+ async def get_funding_rate(self, inst_id: str) -> dict:
2355
+ """Получение текущей ставки финансирования.
2356
+
2357
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-funding-rate
2358
+ """
2359
+ params = {
2360
+ "instId": inst_id,
2361
+ }
2362
+
2363
+ return await self._make_request(
2364
+ "GET",
2365
+ endpoint="/api/v5/public/funding-rate",
2366
+ params=params,
2367
+ )
2368
+
2369
+ async def get_funding_rate_history(
2370
+ self,
2371
+ inst_id: str,
2372
+ before: int | None = None,
2373
+ after: int | None = None,
2374
+ limit: int | None = None,
2375
+ ) -> dict:
2376
+ """Получение истории ставок финансирования за последние три месяца.
2377
+
2378
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-funding-rate-history
2379
+ """
2380
+ params = {
2381
+ "instId": inst_id,
2382
+ "before": before,
2383
+ "after": after,
2384
+ "limit": limit,
2385
+ }
2386
+
2387
+ return await self._make_request(
2388
+ "GET",
2389
+ endpoint="/api/v5/public/funding-rate-history",
2390
+ params=params,
2391
+ )
2392
+
2393
+ async def get_open_interest(
2394
+ self,
2395
+ inst_type: Literal["SWAP", "FUTURES", "OPTION"],
2396
+ inst_family: str | None = None,
2397
+ inst_id: str | None = None,
2398
+ ) -> dict:
2399
+ """Получение общего открытого интереса по контрактам OKX.
2400
+
2401
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-open-interest
2402
+ """
2403
+ params = {
2404
+ "instType": inst_type,
2405
+ "instFamily": inst_family,
2406
+ "instId": inst_id,
2407
+ }
2408
+
2409
+ return await self._make_request(
2410
+ "GET",
2411
+ endpoint="/api/v5/public/open-interest",
2412
+ params=params,
2413
+ )
2414
+
2415
+ async def get_price_limit(self, inst_id: str) -> dict:
2416
+ """Получение верхнего и нижнего лимитов цен для инструмента.
2417
+
2418
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-limit-price
2419
+ """
2420
+ params = {
2421
+ "instId": inst_id,
2422
+ }
2423
+
2424
+ return await self._make_request(
2425
+ "GET",
2426
+ endpoint="/api/v5/public/price-limit",
2427
+ params=params,
2428
+ )
2429
+
2430
+ async def get_option_market_data(
2431
+ self,
2432
+ inst_family: str,
2433
+ exp_time: str | None = None,
2434
+ ) -> dict:
2435
+ """Получение сводных рыночных данных по опционам.
2436
+
2437
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-option-market-data
2438
+ """
2439
+ params = {
2440
+ "instFamily": inst_family,
2441
+ "expTime": exp_time,
2442
+ }
2443
+
2444
+ return await self._make_request(
2445
+ "GET",
2446
+ endpoint="/api/v5/public/opt-summary",
2447
+ params=params,
2448
+ )
2449
+
2450
+ async def get_discount_rate_quota(
2451
+ self,
2452
+ ccy: str | None = None,
2453
+ discount_lv: str | None = None,
2454
+ ) -> dict:
2455
+ """Получение ставок скидок и беспроцентных квот.
2456
+
2457
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-discount-rate-and-interest-free-quota
2458
+ """
2459
+ params = {
2460
+ "ccy": ccy,
2461
+ "discountLv": discount_lv,
2462
+ }
2463
+
2464
+ return await self._make_request(
2465
+ "GET",
2466
+ endpoint="/api/v5/public/discount-rate-interest-free-quota",
2467
+ params=params,
2468
+ )
2469
+
2470
+ async def get_system_time(self) -> dict:
2471
+ """Получение времени сервера OKX.
2472
+
2473
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-system-time
2474
+ """
2475
+ return await self._make_request(
2476
+ "GET",
2477
+ endpoint="/api/v5/public/time",
2478
+ )
2479
+
2480
+ async def get_mark_price(
2481
+ self,
2482
+ inst_type: Literal["MARGIN", "SWAP", "FUTURES", "OPTION"],
2483
+ inst_family: str | None = None,
2484
+ inst_id: str | None = None,
2485
+ ) -> dict:
2486
+ """Получение маржинальной цены инструмента.
2487
+
2488
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-mark-price
2489
+ """
2490
+ params = {
2491
+ "instType": inst_type,
2492
+ "instFamily": inst_family,
2493
+ "instId": inst_id,
2494
+ }
2495
+
2496
+ return await self._make_request(
2497
+ "GET",
2498
+ endpoint="/api/v5/public/mark-price",
2499
+ params=params,
2500
+ )
2501
+
2502
+ async def get_position_tiers(
2503
+ self,
2504
+ inst_type: Literal["MARGIN", "SWAP", "FUTURES", "OPTION"],
2505
+ td_mode: Literal["cross", "isolated"],
2506
+ inst_family: str | None = None,
2507
+ inst_id: str | None = None,
2508
+ ccy: str | None = None,
2509
+ tier: str | None = None,
2510
+ ) -> dict:
2511
+ """Получение уровней позиций и допустимого плеча.
2512
+
2513
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-position-tiers
2514
+ """
2515
+ params = {
2516
+ "instType": inst_type,
2517
+ "tdMode": td_mode,
2518
+ "instFamily": inst_family,
2519
+ "instId": inst_id,
2520
+ "ccy": ccy,
2521
+ "tier": tier,
2522
+ }
2523
+
2524
+ return await self._make_request(
2525
+ "GET",
2526
+ endpoint="/api/v5/public/position-tiers",
2527
+ params=params,
2528
+ )
2529
+
2530
+ async def get_interest_rate_loan_quota(self) -> dict:
2531
+ """Получение ставок и квот заимствования.
2532
+
2533
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-interest-rate-and-loan-quota
2534
+ """
2535
+ return await self._make_request(
2536
+ "GET",
2537
+ endpoint="/api/v5/public/interest-rate-loan-quota",
2538
+ )
2539
+
2540
+ async def get_underlying(self, inst_type: Literal["SWAP", "FUTURES", "OPTION"]) -> dict:
2541
+ """Получение списка базовых активов по типу инструмента.
2542
+
2543
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-underlying
2544
+ """
2545
+ params = {
2546
+ "instType": inst_type,
2547
+ }
2548
+
2549
+ return await self._make_request(
2550
+ "GET",
2551
+ endpoint="/api/v5/public/underlying",
2552
+ params=params,
2553
+ )
2554
+
2555
+ async def get_insurance_fund(
2556
+ self,
2557
+ inst_type: Literal["MARGIN", "SWAP", "FUTURES", "OPTION"],
2558
+ type_: Literal[
2559
+ "regular_update",
2560
+ "liquidation_balance_deposit",
2561
+ "bankruptcy_loss",
2562
+ "platform_revenue",
2563
+ "adl",
2564
+ ]
2565
+ | None = None,
2566
+ inst_family: str | None = None,
2567
+ ccy: str | None = None,
2568
+ before: int | None = None,
2569
+ after: int | None = None,
2570
+ limit: int | None = None,
2571
+ ) -> dict:
2572
+ """Получение данных страхового фонда.
2573
+
2574
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-insurance-fund
2575
+ """
2576
+ params = {
2577
+ "instType": inst_type,
2578
+ "type": type_,
2579
+ "instFamily": inst_family,
2580
+ "ccy": ccy,
2581
+ "before": before,
2582
+ "after": after,
2583
+ "limit": limit,
2584
+ }
2585
+
2586
+ return await self._make_request(
2587
+ "GET",
2588
+ endpoint="/api/v5/public/insurance-fund",
2589
+ params=params,
2590
+ )
2591
+
2592
+ async def convert_contract_coin(
2593
+ self,
2594
+ inst_id: str,
2595
+ sz: str,
2596
+ type_: Literal["1", "2"] | None = None,
2597
+ px: str | None = None,
2598
+ unit: Literal["coin", "usds"] | None = None,
2599
+ op_type: Literal["open", "close"] | None = None,
2600
+ ) -> dict:
2601
+ """Конвертация размера контракта и количества монет.
2602
+
2603
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-unit-convert
2604
+ """
2605
+ params = {
2606
+ "type": type_,
2607
+ "instId": inst_id,
2608
+ "sz": sz,
2609
+ "px": px,
2610
+ "unit": unit,
2611
+ "opType": op_type,
2612
+ }
2613
+
2614
+ return await self._make_request(
2615
+ "GET",
2616
+ endpoint="/api/v5/public/convert-contract-coin",
2617
+ params=params,
2618
+ )
2619
+
2620
+ async def get_option_tick_bands(self, inst_family: str | None = None) -> dict:
2621
+ """Получение доступных ценовых диапазонов опционов.
2622
+
2623
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-option-tick-bands
2624
+ """
2625
+ params = {
2626
+ "instType": "OPTION",
2627
+ "instFamily": inst_family,
2628
+ }
2629
+
2630
+ return await self._make_request(
2631
+ "GET",
2632
+ endpoint="/api/v5/public/instrument-tick-bands",
2633
+ params=params,
2634
+ )
2635
+
2636
+ async def get_premium_history(
2637
+ self,
2638
+ inst_id: str,
2639
+ after: int | None = None,
2640
+ before: int | None = None,
2641
+ limit: int | None = None,
2642
+ ) -> dict:
2643
+ """Получение истории премии индекса за полгода.
2644
+
2645
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-premium-history
2646
+ """
2647
+ params = {
2648
+ "instId": inst_id,
2649
+ "after": after,
2650
+ "before": before,
2651
+ "limit": limit,
2652
+ }
2653
+
2654
+ return await self._make_request(
2655
+ "GET",
2656
+ endpoint="/api/v5/public/premium-history",
2657
+ params=params,
2658
+ )
2659
+
2660
+ async def get_index_tickers(
2661
+ self,
2662
+ quote_ccy: str | None = None,
2663
+ inst_id: str | None = None,
2664
+ ) -> dict:
2665
+ """Получение индексов и ключевых метрик по ним.
2666
+
2667
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-index-tickers
2668
+ """
2669
+ params = {
2670
+ "quoteCcy": quote_ccy,
2671
+ "instId": inst_id,
2672
+ }
2673
+
2674
+ return await self._make_request(
2675
+ "GET",
2676
+ endpoint="/api/v5/market/index-tickers",
2677
+ params=params,
2678
+ )
2679
+
2680
+ async def get_index_candlesticks(
2681
+ self,
2682
+ inst_id: str,
2683
+ after: int | None = None,
2684
+ before: int | None = None,
2685
+ bar: str | None = None,
2686
+ limit: int | None = None,
2687
+ ) -> dict:
2688
+ """Получение свечей по индексным значениям.
2689
+
2690
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-index-candlesticks
2691
+ """
2692
+ params = {
2693
+ "instId": inst_id,
2694
+ "after": after,
2695
+ "before": before,
2696
+ "bar": bar,
2697
+ "limit": limit,
2698
+ }
2699
+
2700
+ return await self._make_request(
2701
+ "GET",
2702
+ endpoint="/api/v5/market/index-candles",
2703
+ params=params,
2704
+ )
2705
+
2706
+ async def get_index_candlesticks_history(
2707
+ self,
2708
+ inst_id: str,
2709
+ after: int | None = None,
2710
+ before: int | None = None,
2711
+ bar: str | None = None,
2712
+ limit: int | None = None,
2713
+ ) -> dict:
2714
+ """Получение исторических свечей по индексам.
2715
+
2716
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-index-candlesticks-history
2717
+ """
2718
+ params = {
2719
+ "instId": inst_id,
2720
+ "after": after,
2721
+ "before": before,
2722
+ "bar": bar,
2723
+ "limit": limit,
2724
+ }
2725
+
2726
+ return await self._make_request(
2727
+ "GET",
2728
+ endpoint="/api/v5/market/history-index-candles",
2729
+ params=params,
2730
+ )
2731
+
2732
+ async def get_mark_price_candlesticks(
2733
+ self,
2734
+ inst_id: str,
2735
+ after: int | None = None,
2736
+ before: int | None = None,
2737
+ bar: str | None = None,
2738
+ limit: int | None = None,
2739
+ ) -> dict:
2740
+ """Получение свечей по маржинальной цене инструмента.
2741
+
2742
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-mark-price-candlesticks
2743
+ """
2744
+ params = {
2745
+ "instId": inst_id,
2746
+ "after": after,
2747
+ "before": before,
2748
+ "bar": bar,
2749
+ "limit": limit,
2750
+ }
2751
+
2752
+ return await self._make_request(
2753
+ "GET",
2754
+ endpoint="/api/v5/market/mark-price-candles",
2755
+ params=params,
2756
+ )
2757
+
2758
+ async def get_mark_price_candlesticks_history(
2759
+ self,
2760
+ inst_id: str,
2761
+ after: int | None = None,
2762
+ before: int | None = None,
2763
+ bar: str | None = None,
2764
+ limit: int | None = None,
2765
+ ) -> dict:
2766
+ """Получение исторических свечей по маржинальной цене.
2767
+
2768
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-mark-price-candlesticks-history
2769
+ """
2770
+ params = {
2771
+ "instId": inst_id,
2772
+ "after": after,
2773
+ "before": before,
2774
+ "bar": bar,
2775
+ "limit": limit,
2776
+ }
2777
+
2778
+ return await self._make_request(
2779
+ "GET",
2780
+ endpoint="/api/v5/market/history-mark-price-candles",
2781
+ params=params,
2782
+ )
2783
+
2784
+ async def get_exchange_rate(self) -> dict:
2785
+ """Получение средневзвешенного курса USD/CNY за две недели.
2786
+
2787
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-exchange-rate
2788
+ """
2789
+ return await self._make_request(
2790
+ "GET",
2791
+ endpoint="/api/v5/market/exchange-rate",
2792
+ )
2793
+
2794
+ async def get_index_components(self, index: str) -> dict:
2795
+ """Получение состава выбранного индекса.
2796
+
2797
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-index-components
2798
+ """
2799
+ params = {
2800
+ "index": index,
2801
+ }
2802
+
2803
+ return await self._make_request(
2804
+ "GET",
2805
+ endpoint="/api/v5/market/index-components",
2806
+ params=params,
2807
+ )
2808
+
2809
+ async def get_economic_calendar(
2810
+ self,
2811
+ region: str | None = None,
2812
+ importance: Literal["1", "2", "3"] | None = None,
2813
+ before: int | None = None,
2814
+ after: int | None = None,
2815
+ limit: int | None = None,
2816
+ ) -> dict:
2817
+ """Получение данных макроэкономического календаря.
2818
+
2819
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-economic-calendar-data
2820
+ """
2821
+ params = {
2822
+ "region": region,
2823
+ "importance": importance,
2824
+ "before": before,
2825
+ "after": after,
2826
+ "limit": limit,
2827
+ }
2828
+
2829
+ return await self._make_request(
2830
+ "GET",
2831
+ endpoint="/api/v5/public/economic-calendar",
2832
+ params=params,
2833
+ signed=True,
2834
+ )
2835
+
2836
+ async def get_market_data_history(
2837
+ self,
2838
+ module: Literal["1", "2", "3", "6"],
2839
+ inst_type: Literal["SPOT", "FUTURES", "SWAP", "OPTION"],
2840
+ begin: int,
2841
+ end: int,
2842
+ inst_id_list: str | None = None,
2843
+ inst_family_list: str | None = None,
2844
+ date_aggr_type: Literal["daily", "monthly"] = "daily",
2845
+ ) -> dict:
2846
+ """Получение ссылок на исторические рыночные данные OKX.
2847
+
2848
+ https://www.okx.com/docs-v5/en/#public-data-rest-api-get-historical-market-data
2849
+ """
2850
+ params = {
2851
+ "module": module,
2852
+ "instType": inst_type,
2853
+ "instIdList": inst_id_list,
2854
+ "instFamilyList": inst_family_list,
2855
+ "dateAggrType": date_aggr_type,
2856
+ "begin": begin,
2857
+ "end": end,
2858
+ }
2859
+
2860
+ return await self._make_request(
2861
+ "GET",
2862
+ endpoint="/api/v5/public/market-data-history",
2863
+ params=params,
280
2864
  )