unicex 0.13.17__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 (93) hide show
  1. unicex/__init__.py +200 -0
  2. unicex/_abc/__init__.py +11 -0
  3. unicex/_abc/exchange_info.py +216 -0
  4. unicex/_abc/uni_client.py +329 -0
  5. unicex/_abc/uni_websocket_manager.py +294 -0
  6. unicex/_base/__init__.py +9 -0
  7. unicex/_base/client.py +214 -0
  8. unicex/_base/websocket.py +261 -0
  9. unicex/binance/__init__.py +27 -0
  10. unicex/binance/adapter.py +202 -0
  11. unicex/binance/client.py +1577 -0
  12. unicex/binance/exchange_info.py +62 -0
  13. unicex/binance/uni_client.py +188 -0
  14. unicex/binance/uni_websocket_manager.py +166 -0
  15. unicex/binance/user_websocket.py +186 -0
  16. unicex/binance/websocket_manager.py +912 -0
  17. unicex/bitget/__init__.py +27 -0
  18. unicex/bitget/adapter.py +188 -0
  19. unicex/bitget/client.py +2514 -0
  20. unicex/bitget/exchange_info.py +48 -0
  21. unicex/bitget/uni_client.py +198 -0
  22. unicex/bitget/uni_websocket_manager.py +275 -0
  23. unicex/bitget/user_websocket.py +7 -0
  24. unicex/bitget/websocket_manager.py +232 -0
  25. unicex/bybit/__init__.py +27 -0
  26. unicex/bybit/adapter.py +208 -0
  27. unicex/bybit/client.py +1876 -0
  28. unicex/bybit/exchange_info.py +53 -0
  29. unicex/bybit/uni_client.py +200 -0
  30. unicex/bybit/uni_websocket_manager.py +291 -0
  31. unicex/bybit/user_websocket.py +7 -0
  32. unicex/bybit/websocket_manager.py +339 -0
  33. unicex/enums.py +273 -0
  34. unicex/exceptions.py +64 -0
  35. unicex/extra.py +335 -0
  36. unicex/gate/__init__.py +27 -0
  37. unicex/gate/adapter.py +178 -0
  38. unicex/gate/client.py +1667 -0
  39. unicex/gate/exchange_info.py +55 -0
  40. unicex/gate/uni_client.py +214 -0
  41. unicex/gate/uni_websocket_manager.py +269 -0
  42. unicex/gate/user_websocket.py +7 -0
  43. unicex/gate/websocket_manager.py +513 -0
  44. unicex/hyperliquid/__init__.py +27 -0
  45. unicex/hyperliquid/adapter.py +261 -0
  46. unicex/hyperliquid/client.py +2315 -0
  47. unicex/hyperliquid/exchange_info.py +119 -0
  48. unicex/hyperliquid/uni_client.py +325 -0
  49. unicex/hyperliquid/uni_websocket_manager.py +269 -0
  50. unicex/hyperliquid/user_websocket.py +7 -0
  51. unicex/hyperliquid/websocket_manager.py +393 -0
  52. unicex/mapper.py +111 -0
  53. unicex/mexc/__init__.py +27 -0
  54. unicex/mexc/_spot_ws_proto/PrivateAccountV3Api_pb2.py +38 -0
  55. unicex/mexc/_spot_ws_proto/PrivateDealsV3Api_pb2.py +38 -0
  56. unicex/mexc/_spot_ws_proto/PrivateOrdersV3Api_pb2.py +38 -0
  57. unicex/mexc/_spot_ws_proto/PublicAggreBookTickerV3Api_pb2.py +38 -0
  58. unicex/mexc/_spot_ws_proto/PublicAggreDealsV3Api_pb2.py +40 -0
  59. unicex/mexc/_spot_ws_proto/PublicAggreDepthsV3Api_pb2.py +40 -0
  60. unicex/mexc/_spot_ws_proto/PublicBookTickerBatchV3Api_pb2.py +38 -0
  61. unicex/mexc/_spot_ws_proto/PublicBookTickerV3Api_pb2.py +38 -0
  62. unicex/mexc/_spot_ws_proto/PublicDealsV3Api_pb2.py +40 -0
  63. unicex/mexc/_spot_ws_proto/PublicFuture_pb2.py +103 -0
  64. unicex/mexc/_spot_ws_proto/PublicIncreaseDepthsBatchV3Api_pb2.py +38 -0
  65. unicex/mexc/_spot_ws_proto/PublicIncreaseDepthsV3Api_pb2.py +40 -0
  66. unicex/mexc/_spot_ws_proto/PublicLimitDepthsV3Api_pb2.py +40 -0
  67. unicex/mexc/_spot_ws_proto/PublicMiniTickerV3Api_pb2.py +38 -0
  68. unicex/mexc/_spot_ws_proto/PublicMiniTickersV3Api_pb2.py +38 -0
  69. unicex/mexc/_spot_ws_proto/PublicSpotKlineV3Api_pb2.py +38 -0
  70. unicex/mexc/_spot_ws_proto/PushDataV3ApiWrapper_pb2.py +38 -0
  71. unicex/mexc/_spot_ws_proto/__init__.py +335 -0
  72. unicex/mexc/adapter.py +239 -0
  73. unicex/mexc/client.py +846 -0
  74. unicex/mexc/exchange_info.py +47 -0
  75. unicex/mexc/uni_client.py +211 -0
  76. unicex/mexc/uni_websocket_manager.py +269 -0
  77. unicex/mexc/user_websocket.py +7 -0
  78. unicex/mexc/websocket_manager.py +456 -0
  79. unicex/okx/__init__.py +27 -0
  80. unicex/okx/adapter.py +150 -0
  81. unicex/okx/client.py +2864 -0
  82. unicex/okx/exchange_info.py +47 -0
  83. unicex/okx/uni_client.py +202 -0
  84. unicex/okx/uni_websocket_manager.py +269 -0
  85. unicex/okx/user_websocket.py +7 -0
  86. unicex/okx/websocket_manager.py +743 -0
  87. unicex/types.py +164 -0
  88. unicex/utils.py +218 -0
  89. unicex-0.13.17.dist-info/METADATA +243 -0
  90. unicex-0.13.17.dist-info/RECORD +93 -0
  91. unicex-0.13.17.dist-info/WHEEL +5 -0
  92. unicex-0.13.17.dist-info/licenses/LICENSE +28 -0
  93. unicex-0.13.17.dist-info/top_level.txt +1 -0
unicex/gate/client.py ADDED
@@ -0,0 +1,1667 @@
1
+ __all__ = ["Client"]
2
+
3
+ import hashlib
4
+ import hmac
5
+ import json
6
+ import time
7
+ from typing import Any, Literal
8
+
9
+ from unicex._base import BaseClient
10
+ from unicex.exceptions import NotAuthorized
11
+ from unicex.types import RequestMethod
12
+ from unicex.utils import dict_to_query_string, filter_params
13
+
14
+
15
+ class Client(BaseClient):
16
+ """Клиент для работы с Gateio API."""
17
+
18
+ _BASE_URL: str = "https://api.gateio.ws"
19
+ """Базовый URL для REST API Gate.io."""
20
+
21
+ def _prepare_request(
22
+ self,
23
+ *,
24
+ method: RequestMethod,
25
+ endpoint: str,
26
+ signed: bool,
27
+ params: dict[str, Any] | None,
28
+ data: dict[str, Any] | None,
29
+ ) -> tuple[str, dict[str, Any] | None, dict[str, Any] | None, dict[str, str]]:
30
+ """Формирует параметры и заголовки для HTTP-запроса."""
31
+ params = filter_params(params) if params else None
32
+ data = filter_params(data) if data else None
33
+ url = f"{self._BASE_URL}{endpoint}"
34
+
35
+ timestamp = str(int(time.time()))
36
+ headers: dict[str, str] = {
37
+ "Accept": "application/json",
38
+ "Content-Type": "application/json",
39
+ "Timestamp": timestamp,
40
+ }
41
+ if self._api_key: # type: ignore[attr-defined]
42
+ headers["KEY"] = self._api_key # type: ignore[attr-defined]
43
+
44
+ if not signed:
45
+ return url, params, data, headers
46
+
47
+ if not self.is_authorized():
48
+ raise NotAuthorized("Api key and api secret is required to private endpoints")
49
+
50
+ payload_string = json.dumps(data, separators=(",", ":")) if data else ""
51
+ query_string = dict_to_query_string(params) if params else ""
52
+ hashed_payload = hashlib.sha512(payload_string.encode("utf-8")).hexdigest()
53
+ signature_body = (
54
+ f"{method.upper()}\n{endpoint}\n{query_string}\n{hashed_payload}\n{timestamp}"
55
+ )
56
+ signature = hmac.new(
57
+ self._api_secret.encode("utf-8"), # type: ignore[attr-defined]
58
+ signature_body.encode("utf-8"),
59
+ hashlib.sha512,
60
+ ).hexdigest()
61
+ headers["SIGN"] = signature
62
+ return url, params, data, headers
63
+
64
+ async def _make_request(
65
+ self,
66
+ method: RequestMethod,
67
+ endpoint: str,
68
+ signed: bool = False,
69
+ *,
70
+ params: dict[str, Any] | None = None,
71
+ data: dict[str, Any] | None = None,
72
+ ) -> Any:
73
+ """Выполняет HTTP-запрос к Gate.io API."""
74
+ url, params, data, headers = self._prepare_request(
75
+ method=method,
76
+ endpoint=endpoint,
77
+ signed=signed,
78
+ params=params,
79
+ data=data,
80
+ )
81
+ return await super()._make_request(
82
+ method=method,
83
+ url=url,
84
+ params=params,
85
+ data=data,
86
+ headers=headers,
87
+ )
88
+
89
+ async def request(
90
+ self,
91
+ method: RequestMethod,
92
+ endpoint: str,
93
+ params: dict[str, Any] | None,
94
+ data: dict[str, Any] | None,
95
+ signed: bool,
96
+ ) -> dict:
97
+ """Специальный метод для выполнения произвольных REST-запросов.
98
+
99
+ Параметры:
100
+ method (`RequestMethod`): HTTP-метод запроса ("GET", "POST" и т.д.).
101
+ endpoint (`str`): Относительный путь эндпоинта Gate.io API.
102
+ params (`dict | None`): Query-параметры запроса.
103
+ data (`dict | None`): Тело запроса.
104
+ signed (`bool`): Нужно ли подписывать запрос.
105
+
106
+ Возвращает:
107
+ `dict`: Ответ Gate.io API.
108
+ """
109
+ return await self._make_request(
110
+ method=method,
111
+ endpoint=endpoint,
112
+ params=params,
113
+ data=data,
114
+ signed=signed,
115
+ )
116
+
117
+ # topic: Spot
118
+
119
+ async def currencies(self) -> dict:
120
+ """Получение информации о всех валютах.
121
+
122
+ https://www.gate.com/docs/developers/apiv4/en/#query-all-currency-information
123
+ """
124
+ return await self._make_request("GET", "/api/v4/spot/currencies")
125
+
126
+ async def currency(self, currency: str) -> dict:
127
+ """Получение информации о конкретной валюте.
128
+
129
+ https://www.gate.com/docs/developers/apiv4/en/#query-single-currency-information
130
+ """
131
+ return await self._make_request("GET", f"/api/v4/spot/currencies/{currency}")
132
+
133
+ async def currency_pairs(self) -> dict:
134
+ """Получение списка поддерживаемых торговых пар.
135
+
136
+ https://www.gate.com/docs/developers/apiv4/en/#query-all-supported-currency-pairs
137
+ """
138
+ return await self._make_request("GET", "/api/v4/spot/currency_pairs")
139
+
140
+ async def currency_pair(self, currency_pair: str) -> dict:
141
+ """Получение информации о конкретной торговой паре.
142
+
143
+ https://www.gate.com/docs/developers/apiv4/en/#query-single-currency-pair-details
144
+ """
145
+ return await self._make_request("GET", f"/api/v4/spot/currency_pairs/{currency_pair}")
146
+
147
+ async def tickers(
148
+ self,
149
+ currency_pair: str | None = None,
150
+ timezone: str | None = None,
151
+ ) -> dict:
152
+ """Получение информации о тикерах торговых пар.
153
+
154
+ https://www.gate.com/docs/developers/apiv4/en/#get-currency-pair-ticker-information
155
+ """
156
+ params = {
157
+ "currency_pair": currency_pair,
158
+ "timezone": timezone,
159
+ }
160
+
161
+ return await self._make_request("GET", "/api/v4/spot/tickers", params=params)
162
+
163
+ async def order_book(
164
+ self,
165
+ currency_pair: str,
166
+ interval: str | None = None,
167
+ limit: int | None = None,
168
+ with_id: bool | None = None,
169
+ ) -> dict:
170
+ """Получение информации о стакане рынка.
171
+
172
+ https://www.gate.com/docs/developers/apiv4/en/#get-market-depth-information
173
+ """
174
+ params = {
175
+ "currency_pair": currency_pair,
176
+ "interval": interval,
177
+ "limit": limit,
178
+ "with_id": with_id,
179
+ }
180
+
181
+ return await self._make_request("GET", "/api/v4/spot/order_book", params=params)
182
+
183
+ async def trades(
184
+ self,
185
+ currency_pair: str,
186
+ limit: int | None = None,
187
+ last_id: str | None = None,
188
+ reverse: bool | None = None,
189
+ from_time: int | None = None,
190
+ to_time: int | None = None,
191
+ page: int | None = None,
192
+ ) -> dict:
193
+ """Получение списка рыночных сделок.
194
+
195
+ https://www.gate.com/docs/developers/apiv4/en/#query-market-transaction-records
196
+ """
197
+ params = {
198
+ "currency_pair": currency_pair,
199
+ "limit": limit,
200
+ "last_id": last_id,
201
+ "reverse": reverse,
202
+ "from": from_time,
203
+ "to": to_time,
204
+ "page": page,
205
+ }
206
+
207
+ return await self._make_request("GET", "/api/v4/spot/trades", params=params)
208
+
209
+ async def candlesticks(
210
+ self,
211
+ currency_pair: str,
212
+ limit: int | None = None,
213
+ from_time: int | None = None,
214
+ to_time: int | None = None,
215
+ interval: str | None = None,
216
+ ) -> dict:
217
+ """Получение данных свечного графика.
218
+
219
+ https://www.gate.com/docs/developers/apiv4/en/#market-k-line-chart
220
+ """
221
+ params = {
222
+ "currency_pair": currency_pair,
223
+ "limit": limit,
224
+ "from": from_time,
225
+ "to": to_time,
226
+ "interval": interval,
227
+ }
228
+
229
+ return await self._make_request("GET", "/api/v4/spot/candlesticks", params=params)
230
+
231
+ async def fee(self, currency_pair: str | None = None) -> dict:
232
+ """Получение комиссий аккаунта по торговым парам.
233
+
234
+ https://www.gate.com/docs/developers/apiv4/en/#query-account-fee-rates
235
+ """
236
+ params = {
237
+ "currency_pair": currency_pair,
238
+ }
239
+
240
+ return await self._make_request("GET", "/api/v4/spot/fee", params=params, signed=True)
241
+
242
+ async def batch_fee(self, currency_pairs: str) -> dict:
243
+ """Получение комиссий аккаунта по нескольким торговым парам.
244
+
245
+ https://www.gate.com/docs/developers/apiv4/en/#batch-query-account-fee-rates
246
+ """
247
+ params = {
248
+ "currency_pairs": currency_pairs,
249
+ }
250
+
251
+ return await self._make_request("GET", "/api/v4/spot/batch_fee", params=params, signed=True)
252
+
253
+ async def accounts(self, currency: str | None = None) -> dict:
254
+ """Получение балансов спотовых аккаунтов.
255
+
256
+ https://www.gate.com/docs/developers/apiv4/en/#list-spot-trading-accounts
257
+ """
258
+ params = {
259
+ "currency": currency,
260
+ }
261
+
262
+ return await self._make_request("GET", "/api/v4/spot/accounts", params=params, signed=True)
263
+
264
+ async def account_book(
265
+ self,
266
+ currency: str | None = None,
267
+ from_time: int | None = None,
268
+ to_time: int | None = None,
269
+ page: int | None = None,
270
+ limit: int | None = None,
271
+ type: str | None = None,
272
+ code: str | None = None,
273
+ ) -> dict:
274
+ """Получение истории транзакций спотового аккаунта.
275
+
276
+ https://www.gate.com/docs/developers/apiv4/en/#query-spot-account-transaction-history
277
+ """
278
+ params = {
279
+ "currency": currency,
280
+ "from": from_time,
281
+ "to": to_time,
282
+ "page": page,
283
+ "limit": limit,
284
+ "type": type,
285
+ "code": code,
286
+ }
287
+
288
+ return await self._make_request(
289
+ "GET", "/api/v4/spot/account_book", params=params, signed=True
290
+ )
291
+
292
+ async def batch_orders(
293
+ self,
294
+ orders: list[dict[str, Any]],
295
+ ) -> dict:
296
+ """Создание нескольких ордеров за один запрос.
297
+
298
+ https://www.gate.com/docs/developers/apiv4/en/#batch-place-orders
299
+ """
300
+ # NOTE: Документация описывает тело запроса как массив ордеров.
301
+ # Клиент Gate.io сериализует данные как объект с ключом "orders".
302
+ data = {
303
+ "orders": orders,
304
+ }
305
+
306
+ return await self._make_request("POST", "/api/v4/spot/batch_orders", data=data, signed=True)
307
+
308
+ async def open_orders(
309
+ self,
310
+ page: int | None = None,
311
+ limit: int | None = None,
312
+ account: str | None = None,
313
+ ) -> dict:
314
+ """Получение списка всех открытых ордеров.
315
+
316
+ https://www.gate.com/docs/developers/apiv4/en/#list-all-open-orders
317
+ """
318
+ params = {
319
+ "page": page,
320
+ "limit": limit,
321
+ "account": account,
322
+ }
323
+
324
+ return await self._make_request(
325
+ "GET", "/api/v4/spot/open_orders", params=params, signed=True
326
+ )
327
+
328
+ async def cross_liquidate_orders(
329
+ self,
330
+ currency_pair: str,
331
+ amount: str,
332
+ price: str,
333
+ text: str | None = None,
334
+ action_mode: str | None = None,
335
+ ) -> dict:
336
+ """Создание ордера для закрытия позиции при отключённой перекрёстной торговле.
337
+
338
+ https://www.gate.com/docs/developers/apiv4/en/#close-position-when-cross-currency-is-disabled
339
+ """
340
+ data = {
341
+ "text": text,
342
+ "currency_pair": currency_pair,
343
+ "amount": amount,
344
+ "price": price,
345
+ "action_mode": action_mode,
346
+ }
347
+
348
+ return await self._make_request(
349
+ "POST", "/api/v4/spot/cross_liquidate_orders", data=data, signed=True
350
+ )
351
+
352
+ async def create_order(
353
+ self,
354
+ currency_pair: str,
355
+ side: str,
356
+ amount: str,
357
+ text: str | None = None,
358
+ type: str | None = None,
359
+ account: str | None = None,
360
+ price: str | None = None,
361
+ time_in_force: str | None = None,
362
+ iceberg: str | None = None,
363
+ auto_borrow: bool | None = None,
364
+ auto_repay: bool | None = None,
365
+ stp_act: str | None = None,
366
+ fee_discount: str | None = None,
367
+ action_mode: str | None = None,
368
+ ) -> dict:
369
+ """Создание нового ордера.
370
+
371
+ https://www.gate.com/docs/developers/apiv4/en/#create-an-order
372
+ """
373
+ data = {
374
+ "text": text,
375
+ "currency_pair": currency_pair,
376
+ "type": type,
377
+ "account": account,
378
+ "side": side,
379
+ "amount": amount,
380
+ "price": price,
381
+ "time_in_force": time_in_force,
382
+ "iceberg": iceberg,
383
+ "auto_borrow": auto_borrow,
384
+ "auto_repay": auto_repay,
385
+ "stp_act": stp_act,
386
+ "fee_discount": fee_discount,
387
+ "action_mode": action_mode,
388
+ }
389
+
390
+ return await self._make_request("POST", "/api/v4/spot/orders", data=data, signed=True)
391
+
392
+ async def orders(
393
+ self,
394
+ currency_pair: str,
395
+ status: str,
396
+ page: int | None = None,
397
+ limit: int | None = None,
398
+ account: str | None = None,
399
+ from_time: int | None = None,
400
+ to_time: int | None = None,
401
+ side: str | None = None,
402
+ ) -> dict:
403
+ """Получение списка ордеров по статусу.
404
+
405
+ https://www.gate.com/docs/developers/apiv4/en/#list-orders
406
+ """
407
+ params = {
408
+ "currency_pair": currency_pair,
409
+ "status": status,
410
+ "page": page,
411
+ "limit": limit,
412
+ "account": account,
413
+ "from": from_time,
414
+ "to": to_time,
415
+ "side": side,
416
+ }
417
+
418
+ return await self._make_request("GET", "/api/v4/spot/orders", params=params, signed=True)
419
+
420
+ async def cancel_all_orders(
421
+ self,
422
+ currency_pair: str | None = None,
423
+ side: str | None = None,
424
+ account: str | None = None,
425
+ action_mode: str | None = None,
426
+ ) -> dict:
427
+ """Отмена всех открытых ордеров по заданным условиям.
428
+
429
+ https://www.gate.com/docs/developers/apiv4/en/#cancel-all-open-orders-in-specified-currency-pair
430
+ """
431
+ params = {
432
+ "currency_pair": currency_pair,
433
+ "side": side,
434
+ "account": account,
435
+ "action_mode": action_mode,
436
+ }
437
+
438
+ return await self._make_request("DELETE", "/api/v4/spot/orders", params=params, signed=True)
439
+
440
+ async def cancel_batch_orders(
441
+ self,
442
+ orders: list[dict[str, Any]],
443
+ ) -> dict:
444
+ """Отмена нескольких ордеров по списку идентификаторов.
445
+
446
+ https://www.gate.com/docs/developers/apiv4/en/#cancel-batch-orders-by-specified-id-list
447
+ """
448
+ # NOTE: Документация описывает тело запроса как массив объектов.
449
+ # В текущей реализации данные оборачиваются в объект с ключом "orders".
450
+ data = {
451
+ "orders": orders,
452
+ }
453
+
454
+ return await self._make_request(
455
+ "POST", "/api/v4/spot/cancel_batch_orders", data=data, signed=True
456
+ )
457
+
458
+ async def order(
459
+ self,
460
+ order_id: str,
461
+ currency_pair: str | None = None,
462
+ account: str | None = None,
463
+ ) -> dict:
464
+ """Получение информации о конкретном ордере.
465
+
466
+ https://www.gate.com/docs/developers/apiv4/en/#query-single-order-details
467
+ """
468
+ params = {
469
+ "currency_pair": currency_pair,
470
+ "account": account,
471
+ }
472
+
473
+ return await self._make_request(
474
+ "GET", f"/api/v4/spot/orders/{order_id}", params=params, signed=True
475
+ )
476
+
477
+ async def amend_order(
478
+ self,
479
+ order_id: str,
480
+ currency_pair: str | None = None,
481
+ account: str | None = None,
482
+ amount: str | None = None,
483
+ price: str | None = None,
484
+ amend_text: str | None = None,
485
+ action_mode: str | None = None,
486
+ ) -> dict:
487
+ """Изменение параметров ордера.
488
+
489
+ https://www.gate.com/docs/developers/apiv4/en/#amend-single-order
490
+ """
491
+ params = {
492
+ "currency_pair": currency_pair,
493
+ "account": account,
494
+ }
495
+ data = {
496
+ "currency_pair": currency_pair,
497
+ "account": account,
498
+ "amount": amount,
499
+ "price": price,
500
+ "amend_text": amend_text,
501
+ "action_mode": action_mode,
502
+ }
503
+
504
+ return await self._make_request(
505
+ "PATCH",
506
+ f"/api/v4/spot/orders/{order_id}",
507
+ params=params,
508
+ data=data,
509
+ signed=True,
510
+ )
511
+
512
+ async def cancel_order(
513
+ self,
514
+ order_id: str,
515
+ currency_pair: str,
516
+ account: str | None = None,
517
+ action_mode: str | None = None,
518
+ ) -> dict:
519
+ """Отмена конкретного ордера.
520
+
521
+ https://www.gate.com/docs/developers/apiv4/en/#cancel-single-order
522
+ """
523
+ params = {
524
+ "currency_pair": currency_pair,
525
+ "account": account,
526
+ "action_mode": action_mode,
527
+ }
528
+
529
+ return await self._make_request(
530
+ "DELETE",
531
+ f"/api/v4/spot/orders/{order_id}",
532
+ params=params,
533
+ signed=True,
534
+ )
535
+
536
+ async def my_trades(
537
+ self,
538
+ currency_pair: str | None = None,
539
+ limit: int | None = None,
540
+ page: int | None = None,
541
+ order_id: str | None = None,
542
+ account: str | None = None,
543
+ from_time: int | None = None,
544
+ to_time: int | None = None,
545
+ ) -> dict:
546
+ """Получение личной истории сделок.
547
+
548
+ https://www.gate.com/docs/developers/apiv4/en/#query-personal-trading-records
549
+ """
550
+ params = {
551
+ "currency_pair": currency_pair,
552
+ "limit": limit,
553
+ "page": page,
554
+ "order_id": order_id,
555
+ "account": account,
556
+ "from": from_time,
557
+ "to": to_time,
558
+ }
559
+
560
+ return await self._make_request("GET", "/api/v4/spot/my_trades", params=params, signed=True)
561
+
562
+ async def countdown_cancel_all(
563
+ self,
564
+ timeout: int,
565
+ currency_pair: str | None = None,
566
+ ) -> dict:
567
+ """Настройка автоматической отмены ордеров по таймеру.
568
+
569
+ https://www.gate.com/docs/developers/apiv4/en/#countdown-cancel-orders
570
+ """
571
+ data = {
572
+ "timeout": timeout,
573
+ "currency_pair": currency_pair,
574
+ }
575
+
576
+ return await self._make_request(
577
+ "POST", "/api/v4/spot/countdown_cancel_all", data=data, signed=True
578
+ )
579
+
580
+ async def amend_batch_orders(
581
+ self,
582
+ orders: list[dict[str, Any]],
583
+ ) -> dict:
584
+ """Изменение параметров нескольких ордеров.
585
+
586
+ https://www.gate.com/docs/developers/apiv4/en/#batch-modification-of-orders
587
+ """
588
+ # NOTE: Формат массива ордеров следует уточнить в зависимости от требований API.
589
+ data = {
590
+ "orders": orders,
591
+ }
592
+
593
+ return await self._make_request(
594
+ "POST", "/api/v4/spot/amend_batch_orders", data=data, signed=True
595
+ )
596
+
597
+ async def insurance_history(
598
+ self,
599
+ business: str,
600
+ currency: str,
601
+ from_time: int,
602
+ to_time: int,
603
+ page: int | None = None,
604
+ limit: int | None = None,
605
+ ) -> dict:
606
+ """Получение истории страхового фонда спотового рынка.
607
+
608
+ https://www.gate.com/docs/developers/apiv4/en/#query-spot-insurance-fund-historical-data
609
+ """
610
+ params = {
611
+ "business": business,
612
+ "currency": currency,
613
+ "from": from_time,
614
+ "to": to_time,
615
+ "page": page,
616
+ "limit": limit,
617
+ }
618
+
619
+ return await self._make_request(
620
+ "GET", "/api/v4/spot/insurance_history", params=params, signed=True
621
+ )
622
+
623
+ async def create_price_order(self, order: dict[str, Any]) -> dict:
624
+ """Создание отложенного ордера с ценовым триггером.
625
+
626
+ https://www.gate.com/docs/developers/apiv4/en/#create-price-triggered-order
627
+ """
628
+ return await self._make_request(
629
+ "POST", "/api/v4/spot/price_orders", data=order, signed=True
630
+ )
631
+
632
+ async def price_orders(
633
+ self,
634
+ status: str,
635
+ market: str | None = None,
636
+ account: str | None = None,
637
+ limit: int | None = None,
638
+ offset: int | None = None,
639
+ ) -> dict:
640
+ """Получение списка активных отложенных ордеров.
641
+
642
+ https://www.gate.com/docs/developers/apiv4/en/#query-running-auto-order-list
643
+ """
644
+ params = {
645
+ "status": status,
646
+ "market": market,
647
+ "account": account,
648
+ "limit": limit,
649
+ "offset": offset,
650
+ }
651
+
652
+ return await self._make_request(
653
+ "GET", "/api/v4/spot/price_orders", params=params, signed=True
654
+ )
655
+
656
+ async def cancel_price_orders(
657
+ self,
658
+ market: str | None = None,
659
+ account: str | None = None,
660
+ ) -> dict:
661
+ """Отмена всех отложенных ордеров.
662
+
663
+ https://www.gate.com/docs/developers/apiv4/en/#cancel-all-auto-orders
664
+ """
665
+ params = {
666
+ "market": market,
667
+ "account": account,
668
+ }
669
+
670
+ return await self._make_request(
671
+ "DELETE", "/api/v4/spot/price_orders", params=params, signed=True
672
+ )
673
+
674
+ async def price_order(self, order_id: str) -> dict:
675
+ """Получение информации о конкретном отложенном ордере.
676
+
677
+ https://www.gate.com/docs/developers/apiv4/en/#query-single-auto-order-details
678
+ """
679
+ return await self._make_request("GET", f"/api/v4/spot/price_orders/{order_id}", signed=True)
680
+
681
+ async def cancel_price_order(self, order_id: str) -> dict:
682
+ """Отмена конкретного отложенного ордера.
683
+
684
+ https://www.gate.com/docs/developers/apiv4/en/#cancel-single-auto-order
685
+ """
686
+ return await self._make_request(
687
+ "DELETE", f"/api/v4/spot/price_orders/{order_id}", signed=True
688
+ )
689
+
690
+ # topic: Futures
691
+
692
+ async def futures_contracts(
693
+ self,
694
+ settle: Literal["usdt", "btc"],
695
+ limit: int | None = None,
696
+ offset: int | None = None,
697
+ ) -> dict:
698
+ """Получение списка фьючерсных контрактов.
699
+
700
+ https://www.gate.com/docs/developers/apiv4/en/#query-all-futures-contracts
701
+ """
702
+ params = {
703
+ "limit": limit,
704
+ "offset": offset,
705
+ }
706
+
707
+ return await self._make_request("GET", f"/api/v4/futures/{settle}/contracts", params=params)
708
+
709
+ async def futures_contract(self, settle: str, contract: str) -> dict:
710
+ """Получение информации о конкретном фьючерсном контракте.
711
+
712
+ https://www.gate.com/docs/developers/apiv4/en/#query-single-contract-information
713
+ """
714
+ return await self._make_request("GET", f"/api/v4/futures/{settle}/contracts/{contract}")
715
+
716
+ async def futures_order_book(
717
+ self,
718
+ settle: str,
719
+ contract: str,
720
+ interval: str | None = None,
721
+ limit: int | None = None,
722
+ with_id: bool | None = None,
723
+ ) -> dict:
724
+ """Получение информации о стакане фьючерсного рынка.
725
+
726
+ https://www.gate.com/docs/developers/apiv4/en/#query-futures-market-depth-information
727
+ """
728
+ params = {
729
+ "contract": contract,
730
+ "interval": interval,
731
+ "limit": limit,
732
+ "with_id": with_id,
733
+ }
734
+
735
+ return await self._make_request(
736
+ "GET", f"/api/v4/futures/{settle}/order_book", params=params
737
+ )
738
+
739
+ async def futures_trades(
740
+ self,
741
+ settle: str,
742
+ contract: str,
743
+ limit: int | None = None,
744
+ offset: int | None = None,
745
+ last_id: str | None = None,
746
+ from_time: int | None = None,
747
+ to_time: int | None = None,
748
+ ) -> dict:
749
+ """Получение списка рыночных сделок по фьючерсам.
750
+
751
+ https://www.gate.com/docs/developers/apiv4/en/#futures-market-transaction-records
752
+ """
753
+ params = {
754
+ "contract": contract,
755
+ "limit": limit,
756
+ "offset": offset,
757
+ "last_id": last_id,
758
+ "from": from_time,
759
+ "to": to_time,
760
+ }
761
+
762
+ return await self._make_request("GET", f"/api/v4/futures/{settle}/trades", params=params)
763
+
764
+ async def futures_candlesticks(
765
+ self,
766
+ settle: str,
767
+ contract: str,
768
+ from_time: int | None = None,
769
+ to_time: int | None = None,
770
+ limit: int | None = None,
771
+ interval: str | None = None,
772
+ timezone: str | None = None,
773
+ ) -> dict:
774
+ """Получение свечных данных по фьючерсному контракту.
775
+
776
+ https://www.gate.com/docs/developers/apiv4/en/#futures-market-k-line-chart
777
+ """
778
+ params = {
779
+ "contract": contract,
780
+ "from": from_time,
781
+ "to": to_time,
782
+ "limit": limit,
783
+ "interval": interval,
784
+ "timezone": timezone,
785
+ }
786
+
787
+ return await self._make_request(
788
+ "GET", f"/api/v4/futures/{settle}/candlesticks", params=params
789
+ )
790
+
791
+ async def futures_premium_index(
792
+ self,
793
+ settle: str,
794
+ contract: str,
795
+ from_time: int | None = None,
796
+ to_time: int | None = None,
797
+ limit: int | None = None,
798
+ interval: str | None = None,
799
+ ) -> dict:
800
+ """Получение данных премиум-индекса.
801
+
802
+ https://www.gate.com/docs/developers/apiv4/en/#premium-index-k-line-chart
803
+ """
804
+ params = {
805
+ "contract": contract,
806
+ "from": from_time,
807
+ "to": to_time,
808
+ "limit": limit,
809
+ "interval": interval,
810
+ }
811
+
812
+ return await self._make_request(
813
+ "GET", f"/api/v4/futures/{settle}/premium_index", params=params
814
+ )
815
+
816
+ async def futures_tickers(
817
+ self,
818
+ settle: str,
819
+ contract: str | None = None,
820
+ ) -> dict:
821
+ """Получение торговой статистики по фьючерсам.
822
+
823
+ https://www.gate.com/docs/developers/apiv4/en/#get-all-futures-trading-statistics
824
+ """
825
+ params = {
826
+ "contract": contract,
827
+ }
828
+
829
+ return await self._make_request("GET", f"/api/v4/futures/{settle}/tickers", params=params)
830
+
831
+ async def futures_funding_rate(
832
+ self,
833
+ settle: str,
834
+ contract: str,
835
+ limit: int | None = None,
836
+ from_time: int | None = None,
837
+ to_time: int | None = None,
838
+ ) -> dict:
839
+ """Получение истории ставок финансирования.
840
+
841
+ https://www.gate.com/docs/developers/apiv4/en/#futures-market-historical-funding-rate
842
+ """
843
+ params = {
844
+ "contract": contract,
845
+ "limit": limit,
846
+ "from": from_time,
847
+ "to": to_time,
848
+ }
849
+
850
+ return await self._make_request(
851
+ "GET", f"/api/v4/futures/{settle}/funding_rate", params=params
852
+ )
853
+
854
+ async def futures_insurance(
855
+ self,
856
+ settle: str,
857
+ limit: int | None = None,
858
+ ) -> dict:
859
+ """Получение истории страхового фонда фьючерсного рынка.
860
+
861
+ https://www.gate.com/docs/developers/apiv4/en/#futures-market-insurance-fund-history
862
+ """
863
+ params = {
864
+ "limit": limit,
865
+ }
866
+
867
+ return await self._make_request("GET", f"/api/v4/futures/{settle}/insurance", params=params)
868
+
869
+ async def futures_contract_stats(
870
+ self,
871
+ settle: str,
872
+ contract: str,
873
+ from_time: int | None = None,
874
+ interval: str | None = None,
875
+ limit: int | None = None,
876
+ ) -> dict:
877
+ """Получение статистики по фьючерсному контракту.
878
+
879
+ https://www.gate.com/docs/developers/apiv4/en/#futures-statistics
880
+ """
881
+ params = {
882
+ "contract": contract,
883
+ "from": from_time,
884
+ "interval": interval,
885
+ "limit": limit,
886
+ }
887
+
888
+ return await self._make_request(
889
+ "GET", f"/api/v4/futures/{settle}/contract_stats", params=params
890
+ )
891
+
892
+ async def futures_index_constituents(self, settle: str, index: str) -> dict:
893
+ """Получение состава индекса.
894
+
895
+ https://www.gate.com/docs/developers/apiv4/en/#query-index-constituents
896
+ """
897
+ return await self._make_request(
898
+ "GET", f"/api/v4/futures/{settle}/index_constituents/{index}"
899
+ )
900
+
901
+ async def futures_liq_orders(
902
+ self,
903
+ settle: str,
904
+ contract: str | None = None,
905
+ from_time: int | None = None,
906
+ to_time: int | None = None,
907
+ limit: int | None = None,
908
+ ) -> dict:
909
+ """Получение истории ликвидаций.
910
+
911
+ https://www.gate.com/docs/developers/apiv4/en/#query-liquidation-order-history
912
+ """
913
+ params = {
914
+ "contract": contract,
915
+ "from": from_time,
916
+ "to": to_time,
917
+ "limit": limit,
918
+ }
919
+
920
+ return await self._make_request(
921
+ "GET", f"/api/v4/futures/{settle}/liq_orders", params=params
922
+ )
923
+
924
+ async def futures_risk_limit_tiers(
925
+ self,
926
+ settle: str,
927
+ contract: str | None = None,
928
+ limit: int | None = None,
929
+ offset: int | None = None,
930
+ ) -> dict:
931
+ """Получение лимитов риска по фьючерсным контрактам.
932
+
933
+ https://www.gate.com/docs/developers/apiv4/en/#query-risk-limit-tiers
934
+ """
935
+ params = {
936
+ "contract": contract,
937
+ "limit": limit,
938
+ "offset": offset,
939
+ }
940
+
941
+ return await self._make_request(
942
+ "GET", f"/api/v4/futures/{settle}/risk_limit_tiers", params=params
943
+ )
944
+
945
+ async def futures_accounts(self, settle: str) -> dict:
946
+ """Получение информации о фьючерсном аккаунте.
947
+
948
+ https://www.gate.com/docs/developers/apiv4/en/#get-futures-account
949
+ """
950
+ return await self._make_request("GET", f"/api/v4/futures/{settle}/accounts", signed=True)
951
+
952
+ async def futures_account_book(
953
+ self,
954
+ settle: str,
955
+ contract: str | None = None,
956
+ limit: int | None = None,
957
+ offset: int | None = None,
958
+ from_time: int | None = None,
959
+ to_time: int | None = None,
960
+ type_: str | None = None,
961
+ ) -> dict:
962
+ """Получение истории изменений фьючерсного аккаунта.
963
+
964
+ https://www.gate.com/docs/developers/apiv4/en/#query-futures-account-change-history
965
+ """
966
+ params = {
967
+ "contract": contract,
968
+ "limit": limit,
969
+ "offset": offset,
970
+ "from": from_time,
971
+ "to": to_time,
972
+ "type": type_,
973
+ }
974
+
975
+ return await self._make_request(
976
+ "GET", f"/api/v4/futures/{settle}/account_book", params=params, signed=True
977
+ )
978
+
979
+ async def futures_positions(
980
+ self,
981
+ settle: str,
982
+ holding: bool | None = None,
983
+ limit: int | None = None,
984
+ offset: int | None = None,
985
+ ) -> dict:
986
+ """Получение списка позиций пользователя.
987
+
988
+ https://www.gate.com/docs/developers/apiv4/en/#get-user-position-list
989
+ """
990
+ params = {
991
+ "holding": holding,
992
+ "limit": limit,
993
+ "offset": offset,
994
+ }
995
+
996
+ return await self._make_request(
997
+ "GET", f"/api/v4/futures/{settle}/positions", params=params, signed=True
998
+ )
999
+
1000
+ async def futures_position(
1001
+ self,
1002
+ settle: str,
1003
+ contract: str,
1004
+ ) -> dict:
1005
+ """Получение информации о позиции по контракту.
1006
+
1007
+ https://www.gate.com/docs/developers/apiv4/en/#get-single-position-information
1008
+ """
1009
+ return await self._make_request(
1010
+ "GET", f"/api/v4/futures/{settle}/positions/{contract}", signed=True
1011
+ )
1012
+
1013
+ async def futures_update_margin(
1014
+ self,
1015
+ settle: str,
1016
+ contract: str,
1017
+ change: str,
1018
+ ) -> dict:
1019
+ """Изменение маржи позиции.
1020
+
1021
+ https://www.gate.com/docs/developers/apiv4/en/#update-position-margin
1022
+ """
1023
+ params = {
1024
+ "change": change,
1025
+ }
1026
+
1027
+ return await self._make_request(
1028
+ "POST",
1029
+ f"/api/v4/futures/{settle}/positions/{contract}/margin",
1030
+ params=params,
1031
+ signed=True,
1032
+ )
1033
+
1034
+ async def futures_update_leverage(
1035
+ self,
1036
+ settle: str,
1037
+ contract: str,
1038
+ leverage: str,
1039
+ cross_leverage_limit: str | None = None,
1040
+ pid: int | None = None,
1041
+ ) -> dict:
1042
+ """Изменение кредита позиции.
1043
+
1044
+ https://www.gate.com/docs/developers/apiv4/en/#update-position-leverage
1045
+ """
1046
+ params = {
1047
+ "leverage": leverage,
1048
+ "cross_leverage_limit": cross_leverage_limit,
1049
+ "pid": pid,
1050
+ }
1051
+
1052
+ return await self._make_request(
1053
+ "POST",
1054
+ f"/api/v4/futures/{settle}/positions/{contract}/leverage",
1055
+ params=params,
1056
+ signed=True,
1057
+ )
1058
+
1059
+ async def futures_switch_cross_mode(
1060
+ self,
1061
+ settle: str,
1062
+ mode: str,
1063
+ contract: str,
1064
+ ) -> dict:
1065
+ """Переключение режима маржи позиции.
1066
+
1067
+ https://www.gate.com/docs/developers/apiv4/en/#switch-position-margin-mode
1068
+ """
1069
+ data = {
1070
+ "mode": mode,
1071
+ "contract": contract,
1072
+ }
1073
+
1074
+ return await self._make_request(
1075
+ "POST", f"/api/v4/futures/{settle}/positions/cross_mode", data=data, signed=True
1076
+ )
1077
+
1078
+ async def futures_dual_comp_switch_cross_mode(
1079
+ self,
1080
+ settle: str,
1081
+ mode: str,
1082
+ contract: str,
1083
+ ) -> dict:
1084
+ """Переключение режима маржи в хедж-режиме.
1085
+
1086
+ https://www.gate.com/docs/developers/apiv4/en/#switch-between-cross-and-isolated-margin-modes-under-hedge-mode
1087
+ """
1088
+ data = {
1089
+ "mode": mode,
1090
+ "contract": contract,
1091
+ }
1092
+
1093
+ return await self._make_request(
1094
+ "POST",
1095
+ f"/api/v4/futures/{settle}/dual_comp/positions/cross_mode",
1096
+ data=data,
1097
+ signed=True,
1098
+ )
1099
+
1100
+ async def futures_update_risk_limit(
1101
+ self,
1102
+ settle: str,
1103
+ contract: str,
1104
+ risk_limit: str,
1105
+ ) -> dict:
1106
+ """Изменение лимита риска позиции.
1107
+
1108
+ https://www.gate.com/docs/developers/apiv4/en/#update-position-risk-limit
1109
+ """
1110
+ params = {
1111
+ "risk_limit": risk_limit,
1112
+ }
1113
+
1114
+ return await self._make_request(
1115
+ "POST",
1116
+ f"/api/v4/futures/{settle}/positions/{contract}/risk_limit",
1117
+ params=params,
1118
+ signed=True,
1119
+ )
1120
+
1121
+ async def futures_set_dual_mode(
1122
+ self,
1123
+ settle: str,
1124
+ dual_mode: bool,
1125
+ ) -> dict:
1126
+ """Настройка режима двойных позиций.
1127
+
1128
+ https://www.gate.com/docs/developers/apiv4/en/#set-position-mode
1129
+ """
1130
+ params = {
1131
+ "dual_mode": dual_mode,
1132
+ }
1133
+
1134
+ return await self._make_request(
1135
+ "POST", f"/api/v4/futures/{settle}/dual_mode", params=params, signed=True
1136
+ )
1137
+
1138
+ async def futures_dual_comp_position(
1139
+ self,
1140
+ settle: str,
1141
+ contract: str,
1142
+ ) -> dict:
1143
+ """Получение информации о позиции в двойном режиме.
1144
+
1145
+ https://www.gate.com/docs/developers/apiv4/en/#get-position-information-in-dual-mode
1146
+ """
1147
+ return await self._make_request(
1148
+ "GET", f"/api/v4/futures/{settle}/dual_comp/positions/{contract}", signed=True
1149
+ )
1150
+
1151
+ async def futures_dual_comp_update_margin(
1152
+ self,
1153
+ settle: str,
1154
+ contract: str,
1155
+ change: str,
1156
+ dual_side: str,
1157
+ ) -> dict:
1158
+ """Изменение маржи позиции в двойном режиме.
1159
+
1160
+ https://www.gate.com/docs/developers/apiv4/en/#update-position-margin-in-dual-mode
1161
+ """
1162
+ params = {
1163
+ "change": change,
1164
+ "dual_side": dual_side,
1165
+ }
1166
+
1167
+ return await self._make_request(
1168
+ "POST",
1169
+ f"/api/v4/futures/{settle}/dual_comp/positions/{contract}/margin",
1170
+ params=params,
1171
+ signed=True,
1172
+ )
1173
+
1174
+ async def futures_dual_comp_update_leverage(
1175
+ self,
1176
+ settle: str,
1177
+ contract: str,
1178
+ leverage: str,
1179
+ cross_leverage_limit: str | None = None,
1180
+ ) -> dict:
1181
+ """Изменение плеча позиции в двойном режиме.
1182
+
1183
+ https://www.gate.com/docs/developers/apiv4/en/#update-position-leverage-in-dual-mode
1184
+ """
1185
+ params = {
1186
+ "leverage": leverage,
1187
+ "cross_leverage_limit": cross_leverage_limit,
1188
+ }
1189
+
1190
+ return await self._make_request(
1191
+ "POST",
1192
+ f"/api/v4/futures/{settle}/dual_comp/positions/{contract}/leverage",
1193
+ params=params,
1194
+ signed=True,
1195
+ )
1196
+
1197
+ async def futures_dual_comp_update_risk_limit(
1198
+ self,
1199
+ settle: str,
1200
+ contract: str,
1201
+ risk_limit: str,
1202
+ ) -> dict:
1203
+ """Изменение лимита риска в двойном режиме.
1204
+
1205
+ https://www.gate.com/docs/developers/apiv4/en/#update-position-risk-limit-in-dual-mode
1206
+ """
1207
+ params = {
1208
+ "risk_limit": risk_limit,
1209
+ }
1210
+
1211
+ return await self._make_request(
1212
+ "POST",
1213
+ f"/api/v4/futures/{settle}/dual_comp/positions/{contract}/risk_limit",
1214
+ params=params,
1215
+ signed=True,
1216
+ )
1217
+
1218
+ async def futures_create_order(self, settle: str, order: dict[str, Any]) -> dict:
1219
+ """Создание фьючерсного ордера.
1220
+
1221
+ https://www.gate.com/docs/developers/apiv4/en/#place-futures-order
1222
+ """
1223
+ return await self._make_request(
1224
+ "POST", f"/api/v4/futures/{settle}/orders", data=order, signed=True
1225
+ )
1226
+
1227
+ async def futures_orders(
1228
+ self,
1229
+ settle: str,
1230
+ status: str,
1231
+ contract: str | None = None,
1232
+ limit: int | None = None,
1233
+ offset: int | None = None,
1234
+ last_id: str | None = None,
1235
+ ) -> dict:
1236
+ """Получение списка фьючерсных ордеров по статусу.
1237
+
1238
+ https://www.gate.com/docs/developers/apiv4/en/#query-futures-order-list
1239
+ """
1240
+ params = {
1241
+ "contract": contract,
1242
+ "status": status,
1243
+ "limit": limit,
1244
+ "offset": offset,
1245
+ "last_id": last_id,
1246
+ }
1247
+
1248
+ return await self._make_request(
1249
+ "GET", f"/api/v4/futures/{settle}/orders", params=params, signed=True
1250
+ )
1251
+
1252
+ async def futures_cancel_all_orders(
1253
+ self,
1254
+ settle: str,
1255
+ contract: str,
1256
+ side: str | None = None,
1257
+ exclude_reduce_only: bool | None = None,
1258
+ text: str | None = None,
1259
+ ) -> dict:
1260
+ """Отмена всех открытых фьючерсных ордеров по контракту.
1261
+
1262
+ https://www.gate.com/docs/developers/apiv4/en/#cancel-all-orders-with-open-status
1263
+ """
1264
+ params = {
1265
+ "contract": contract,
1266
+ "side": side,
1267
+ "exclude_reduce_only": exclude_reduce_only,
1268
+ "text": text,
1269
+ }
1270
+
1271
+ return await self._make_request(
1272
+ "DELETE", f"/api/v4/futures/{settle}/orders", params=params, signed=True
1273
+ )
1274
+
1275
+ async def futures_orders_timerange(
1276
+ self,
1277
+ settle: str,
1278
+ contract: str | None = None,
1279
+ from_time: int | None = None,
1280
+ to_time: int | None = None,
1281
+ limit: int | None = None,
1282
+ offset: int | None = None,
1283
+ ) -> dict:
1284
+ """Получение списка фьючерсных ордеров за период.
1285
+
1286
+ https://www.gate.com/docs/developers/apiv4/en/#query-futures-order-list-by-time-range
1287
+ """
1288
+ params = {
1289
+ "contract": contract,
1290
+ "from": from_time,
1291
+ "to": to_time,
1292
+ "limit": limit,
1293
+ "offset": offset,
1294
+ }
1295
+
1296
+ return await self._make_request(
1297
+ "GET", f"/api/v4/futures/{settle}/orders_timerange", params=params, signed=True
1298
+ )
1299
+
1300
+ async def futures_create_orders_batch(
1301
+ self,
1302
+ settle: str,
1303
+ orders: list[dict[str, Any]],
1304
+ ) -> dict:
1305
+ """Создание нескольких фьючерсных ордеров за один запрос.
1306
+
1307
+ https://www.gate.com/docs/developers/apiv4/en/#place-batch-futures-orders
1308
+ """
1309
+ # NOTE: Документация требует массив объектов ордеров, запрос сериализуется как JSON-массив.
1310
+ return await self._make_request(
1311
+ "POST",
1312
+ f"/api/v4/futures/{settle}/batch_orders",
1313
+ data=orders, # type: ignore
1314
+ signed=True,
1315
+ )
1316
+
1317
+ async def futures_order(
1318
+ self,
1319
+ settle: str,
1320
+ order_id: str,
1321
+ ) -> dict:
1322
+ """Получение информации о фьючерсном ордере.
1323
+
1324
+ https://www.gate.com/docs/developers/apiv4/en/#query-single-order-details
1325
+ """
1326
+ return await self._make_request(
1327
+ "GET", f"/api/v4/futures/{settle}/orders/{order_id}", signed=True
1328
+ )
1329
+
1330
+ async def futures_cancel_order(
1331
+ self,
1332
+ settle: str,
1333
+ order_id: str,
1334
+ ) -> dict:
1335
+ """Отмена конкретного фьючерсного ордера.
1336
+
1337
+ https://www.gate.com/docs/developers/apiv4/en/#cancel-single-order
1338
+ """
1339
+ return await self._make_request(
1340
+ "DELETE", f"/api/v4/futures/{settle}/orders/{order_id}", signed=True
1341
+ )
1342
+
1343
+ async def futures_amend_order(
1344
+ self,
1345
+ settle: str,
1346
+ order_id: str,
1347
+ size: int | None = None,
1348
+ price: str | None = None,
1349
+ amend_text: str | None = None,
1350
+ text: str | None = None,
1351
+ ) -> dict:
1352
+ """Изменение параметров фьючерсного ордера.
1353
+
1354
+ https://www.gate.com/docs/developers/apiv4/en/#amend-single-order
1355
+ """
1356
+ data = {
1357
+ "size": size,
1358
+ "price": price,
1359
+ "amend_text": amend_text,
1360
+ "text": text,
1361
+ }
1362
+
1363
+ return await self._make_request(
1364
+ "PUT",
1365
+ f"/api/v4/futures/{settle}/orders/{order_id}",
1366
+ data=data,
1367
+ signed=True,
1368
+ )
1369
+
1370
+ async def futures_my_trades(
1371
+ self,
1372
+ settle: str,
1373
+ contract: str | None = None,
1374
+ order: int | None = None,
1375
+ limit: int | None = None,
1376
+ offset: int | None = None,
1377
+ last_id: str | None = None,
1378
+ ) -> dict:
1379
+ """Получение личной истории сделок по фьючерсам.
1380
+
1381
+ https://www.gate.com/docs/developers/apiv4/en/#query-personal-trading-records
1382
+ """
1383
+ params = {
1384
+ "contract": contract,
1385
+ "order": order,
1386
+ "limit": limit,
1387
+ "offset": offset,
1388
+ "last_id": last_id,
1389
+ }
1390
+
1391
+ return await self._make_request(
1392
+ "GET", f"/api/v4/futures/{settle}/my_trades", params=params, signed=True
1393
+ )
1394
+
1395
+ async def futures_my_trades_timerange(
1396
+ self,
1397
+ settle: str,
1398
+ contract: str | None = None,
1399
+ from_time: int | None = None,
1400
+ to_time: int | None = None,
1401
+ limit: int | None = None,
1402
+ offset: int | None = None,
1403
+ role: str | None = None,
1404
+ ) -> dict:
1405
+ """Получение личной истории сделок за период.
1406
+
1407
+ https://www.gate.com/docs/developers/apiv4/en/#query-personal-trading-records-by-time-range
1408
+ """
1409
+ params = {
1410
+ "contract": contract,
1411
+ "from": from_time,
1412
+ "to": to_time,
1413
+ "limit": limit,
1414
+ "offset": offset,
1415
+ "role": role,
1416
+ }
1417
+
1418
+ return await self._make_request(
1419
+ "GET", f"/api/v4/futures/{settle}/my_trades_timerange", params=params, signed=True
1420
+ )
1421
+
1422
+ async def futures_position_close(
1423
+ self,
1424
+ settle: str,
1425
+ contract: str | None = None,
1426
+ limit: int | None = None,
1427
+ offset: int | None = None,
1428
+ from_time: int | None = None,
1429
+ to_time: int | None = None,
1430
+ side: str | None = None,
1431
+ pnl: str | None = None,
1432
+ ) -> dict:
1433
+ """Получение истории закрытых позиций.
1434
+
1435
+ https://www.gate.com/docs/developers/apiv4/en/#query-position-close-history
1436
+ """
1437
+ params = {
1438
+ "contract": contract,
1439
+ "limit": limit,
1440
+ "offset": offset,
1441
+ "from": from_time,
1442
+ "to": to_time,
1443
+ "side": side,
1444
+ "pnl": pnl,
1445
+ }
1446
+
1447
+ return await self._make_request(
1448
+ "GET", f"/api/v4/futures/{settle}/position_close", params=params, signed=True
1449
+ )
1450
+
1451
+ async def futures_liquidates(
1452
+ self,
1453
+ settle: str,
1454
+ contract: str | None = None,
1455
+ limit: int | None = None,
1456
+ offset: int | None = None,
1457
+ from_time: int | None = None,
1458
+ to_time: int | None = None,
1459
+ at: int | None = None,
1460
+ ) -> dict:
1461
+ """Получение истории ликвидаций аккаунта.
1462
+
1463
+ https://www.gate.com/docs/developers/apiv4/en/#query-liquidation-history
1464
+ """
1465
+ params = {
1466
+ "contract": contract,
1467
+ "limit": limit,
1468
+ "offset": offset,
1469
+ "from": from_time,
1470
+ "to": to_time,
1471
+ "at": at,
1472
+ }
1473
+
1474
+ return await self._make_request(
1475
+ "GET", f"/api/v4/futures/{settle}/liquidates", params=params, signed=True
1476
+ )
1477
+
1478
+ async def futures_auto_deleverages(
1479
+ self,
1480
+ settle: str,
1481
+ contract: str | None = None,
1482
+ limit: int | None = None,
1483
+ offset: int | None = None,
1484
+ from_time: int | None = None,
1485
+ to_time: int | None = None,
1486
+ at: int | None = None,
1487
+ ) -> dict:
1488
+ """Получение истории автоматического снижения плеча (ADL).
1489
+
1490
+ https://www.gate.com/docs/developers/apiv4/en/#query-adl-auto-deleveraging-order-information
1491
+ """
1492
+ params = {
1493
+ "contract": contract,
1494
+ "limit": limit,
1495
+ "offset": offset,
1496
+ "from": from_time,
1497
+ "to": to_time,
1498
+ "at": at,
1499
+ }
1500
+
1501
+ return await self._make_request(
1502
+ "GET", f"/api/v4/futures/{settle}/auto_deleverages", params=params, signed=True
1503
+ )
1504
+
1505
+ async def futures_countdown_cancel_all(
1506
+ self,
1507
+ settle: str,
1508
+ timeout: int,
1509
+ contract: str | None = None,
1510
+ ) -> dict:
1511
+ """Настройка таймера автоматической отмены фьючерсных ордеров.
1512
+
1513
+ https://www.gate.com/docs/developers/apiv4/en/#countdown-cancel-orders
1514
+ """
1515
+ data = {
1516
+ "timeout": timeout,
1517
+ "contract": contract,
1518
+ }
1519
+
1520
+ return await self._make_request(
1521
+ "POST", f"/api/v4/futures/{settle}/countdown_cancel_all", data=data, signed=True
1522
+ )
1523
+
1524
+ async def futures_fee(
1525
+ self,
1526
+ settle: str,
1527
+ contract: str | None = None,
1528
+ ) -> dict:
1529
+ """Получение ставок комиссий на фьючерсном рынке.
1530
+
1531
+ https://www.gate.com/docs/developers/apiv4/en/#query-futures-market-trading-fee-rates
1532
+ """
1533
+ params = {
1534
+ "contract": contract,
1535
+ }
1536
+
1537
+ return await self._make_request(
1538
+ "GET", f"/api/v4/futures/{settle}/fee", params=params, signed=True
1539
+ )
1540
+
1541
+ async def futures_cancel_orders_batch(
1542
+ self,
1543
+ settle: str,
1544
+ order_ids: list[str],
1545
+ ) -> dict:
1546
+ """Отмена списка фьючерсных ордеров по идентификаторам.
1547
+
1548
+ https://www.gate.com/docs/developers/apiv4/en/#cancel-batch-orders-by-specified-id-list
1549
+ """
1550
+ return await self._make_request(
1551
+ "POST",
1552
+ f"/api/v4/futures/{settle}/batch_cancel_orders",
1553
+ data=order_ids, # type: ignore
1554
+ signed=True,
1555
+ )
1556
+
1557
+ async def futures_amend_orders_batch(
1558
+ self,
1559
+ settle: str,
1560
+ orders: list[dict[str, Any]],
1561
+ ) -> dict:
1562
+ """Изменение параметров нескольких фьючерсных ордеров.
1563
+
1564
+ https://www.gate.com/docs/developers/apiv4/en/#batch-modify-orders-by-specified-ids
1565
+ """
1566
+ return await self._make_request(
1567
+ "POST",
1568
+ f"/api/v4/futures/{settle}/batch_amend_orders",
1569
+ data=orders, # type: ignore
1570
+ signed=True,
1571
+ )
1572
+
1573
+ async def futures_risk_limit_table(
1574
+ self,
1575
+ settle: str,
1576
+ table_id: str,
1577
+ ) -> dict:
1578
+ """Получение таблицы лимитов риска по идентификатору.
1579
+
1580
+ https://www.gate.com/docs/developers/apiv4/en/#query-risk-limit-table-by-table-id
1581
+ """
1582
+ params = {
1583
+ "table_id": table_id,
1584
+ }
1585
+
1586
+ return await self._make_request(
1587
+ "GET", f"/api/v4/futures/{settle}/risk_limit_table", params=params
1588
+ )
1589
+
1590
+ async def futures_create_price_order(
1591
+ self,
1592
+ settle: str,
1593
+ order: dict[str, Any],
1594
+ ) -> dict:
1595
+ """Создание фьючерсного ордера с ценовым триггером.
1596
+
1597
+ https://www.gate.com/docs/developers/apiv4/en/#create-price-triggered-order
1598
+ """
1599
+ return await self._make_request(
1600
+ "POST", f"/api/v4/futures/{settle}/price_orders", data=order, signed=True
1601
+ )
1602
+
1603
+ async def futures_price_orders(
1604
+ self,
1605
+ settle: str,
1606
+ status: str,
1607
+ contract: str | None = None,
1608
+ limit: int | None = None,
1609
+ offset: int | None = None,
1610
+ ) -> dict:
1611
+ """Получение списка отложенных ордеров по фьючерсам.
1612
+
1613
+ https://www.gate.com/docs/developers/apiv4/en/#query-auto-order-list
1614
+ """
1615
+ params = {
1616
+ "status": status,
1617
+ "contract": contract,
1618
+ "limit": limit,
1619
+ "offset": offset,
1620
+ }
1621
+
1622
+ return await self._make_request(
1623
+ "GET", f"/api/v4/futures/{settle}/price_orders", params=params, signed=True
1624
+ )
1625
+
1626
+ async def futures_cancel_price_orders(
1627
+ self,
1628
+ settle: str,
1629
+ contract: str | None = None,
1630
+ ) -> dict:
1631
+ """Отмена всех отложенных фьючерсных ордеров.
1632
+
1633
+ https://www.gate.com/docs/developers/apiv4/en/#cancel-all-auto-orders
1634
+ """
1635
+ params = {
1636
+ "contract": contract,
1637
+ }
1638
+
1639
+ return await self._make_request(
1640
+ "DELETE", f"/api/v4/futures/{settle}/price_orders", params=params, signed=True
1641
+ )
1642
+
1643
+ async def futures_price_order(
1644
+ self,
1645
+ settle: str,
1646
+ order_id: str,
1647
+ ) -> dict:
1648
+ """Получение информации о ценовом триггерном ордере.
1649
+
1650
+ https://www.gate.com/docs/developers/apiv4/en/#query-single-auto-order-details
1651
+ """
1652
+ return await self._make_request(
1653
+ "GET", f"/api/v4/futures/{settle}/price_orders/{order_id}", signed=True
1654
+ )
1655
+
1656
+ async def futures_cancel_price_order(
1657
+ self,
1658
+ settle: str,
1659
+ order_id: str,
1660
+ ) -> dict:
1661
+ """Отмена ценового триггерного ордера.
1662
+
1663
+ https://www.gate.com/docs/developers/apiv4/en/#cancel-single-auto-order
1664
+ """
1665
+ return await self._make_request(
1666
+ "DELETE", f"/api/v4/futures/{settle}/price_orders/{order_id}", signed=True
1667
+ )