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/mexc/client.py ADDED
@@ -0,0 +1,846 @@
1
+ __all__ = ["Client"]
2
+
3
+
4
+ import time
5
+ from typing import Any
6
+
7
+ from unicex._base import BaseClient
8
+ from unicex.exceptions import NotAuthorized
9
+ from unicex.types import RequestMethod
10
+ from unicex.utils import dict_to_query_string, filter_params, generate_hmac_sha256_signature
11
+
12
+
13
+ class Client(BaseClient):
14
+ """Клиент для работы с MEXC Spot API."""
15
+
16
+ _BASE_SPOT_URL: str = "https://api.mexc.com"
17
+ """Базовый URL для REST API MEXC."""
18
+
19
+ _BASE_FUTURES_URL: str = "https://contract.mexc.com"
20
+ """Базовый URL для фьючерсного REST API MEXC."""
21
+
22
+ _RECV_WINDOW: str = "5000"
23
+ """Стандартный интервал времени для получения ответа от сервера."""
24
+
25
+ def _get_headers(self, signed: bool = False) -> dict:
26
+ """Формирует заголовки запроса."""
27
+ headers = {"Content-Type": "application/json"}
28
+ if signed:
29
+ if not self._api_key:
30
+ raise NotAuthorized("API key is required for private endpoints.")
31
+ headers["X-MEXC-APIKEY"] = self._api_key
32
+ return headers
33
+
34
+ def _generate_signature(self, payload: dict) -> str:
35
+ """Генерирует подпись на основе данных запроса."""
36
+ if not self.is_authorized():
37
+ raise NotAuthorized("Api key and api secret is required to private endpoints")
38
+
39
+ query_string = dict_to_query_string(payload)
40
+ return generate_hmac_sha256_signature(
41
+ self._api_secret, # type: ignore[attr-defined]
42
+ query_string,
43
+ "hex",
44
+ )
45
+
46
+ async def _make_request(
47
+ self,
48
+ method: RequestMethod,
49
+ url: str,
50
+ *,
51
+ params: dict[str, Any] | None = None,
52
+ signed: bool = False,
53
+ ) -> Any:
54
+ """Выполняет HTTP-запрос к эндпоинтам Mexc API.
55
+
56
+ Если signed=True, формируется подпись для приватных endpoint'ов:
57
+ - Если переданы params — подпись добавляется в параметры запроса.
58
+ - Если передан data — подпись добавляется в тело запроса.
59
+
60
+ Если signed=False, запрос отправляется как публичный.
61
+
62
+ Параметры:
63
+ method (`str`): HTTP метод ("GET", "POST", "DELETE" и т.д.).
64
+ url (`str`): Полный URL эндпоинта Mexc API.
65
+ params (`dict | None`): Query-параметры.
66
+ signed (`bool`): Нужно ли подписывать запрос.
67
+
68
+ Возвращает:
69
+ `dict`: Ответ в формате JSON.
70
+ """
71
+ # Фильтруем параметры
72
+ payload = filter_params(params) if params else {}
73
+
74
+ # Генериуем подпись, если запрос авторизованый
75
+ if signed:
76
+ # Генерируем подпись
77
+ payload["timestamp"] = int(time.time() * 1000)
78
+ payload["recvWindow"] = self._RECV_WINDOW
79
+ payload["signature"] = self._generate_signature(payload)
80
+
81
+ # Формируем заголовки запроса
82
+ headers = self._get_headers(signed=signed)
83
+
84
+ return await super()._make_request(
85
+ method=method,
86
+ url=url,
87
+ params=payload,
88
+ headers=headers,
89
+ )
90
+
91
+ async def request(self, method: RequestMethod, url: str, params: dict, signed: bool) -> dict:
92
+ """Специальный метод для выполнения запросов на эндпоинты, которые не обернуты в клиенте.
93
+
94
+ Параметры:
95
+ method (RequestMethod): Метод запроса (GET, POST, PUT, DELETE).
96
+ url (str): URL эндпоинта.
97
+ params (dict): Параметры запроса.
98
+ signed (bool): Флаг, указывающий, требуется ли подпись запроса.
99
+
100
+ Возвращает:
101
+ `dict`: Ответ в формате JSON.
102
+ """
103
+ return await self._make_request(method=method, url=url, params=params, signed=signed)
104
+
105
+ # topic: Market
106
+ async def ping(self) -> dict:
107
+ """Проверка соединения с REST API.
108
+
109
+ https://www.mexc.com/api-docs/spot-v3/market-data-endpoints#test-connectivity
110
+ """
111
+ return await self._make_request("GET", self._BASE_SPOT_URL + "/api/v3/ping")
112
+
113
+ async def server_time(self) -> dict:
114
+ """Получение текущего серверного времени.
115
+
116
+ https://www.mexc.com/api-docs/spot-v3/market-data-endpoints#check-server-time
117
+ """
118
+ return await self._make_request("GET", self._BASE_SPOT_URL + "/api/v3/time")
119
+
120
+ async def default_symbols(self) -> dict:
121
+ """Получение списка торговых пар по умолчанию.
122
+
123
+ https://www.mexc.com/api-docs/spot-v3/market-data-endpoints#api-default-symbol
124
+ """
125
+ return await self._make_request("GET", self._BASE_SPOT_URL + "/api/v3/defaultSymbols")
126
+
127
+ async def exchange_info(
128
+ self,
129
+ symbol: str | None = None,
130
+ symbols: list[str] | None = None,
131
+ ) -> dict:
132
+ """Получение торговых правил биржи и информации о символах.
133
+
134
+ https://www.mexc.com/api-docs/spot-v3/market-data-endpoints#exchange-information
135
+ """
136
+ params = {
137
+ "symbol": symbol,
138
+ "symbols": symbols,
139
+ }
140
+
141
+ return await self._make_request(
142
+ "GET", self._BASE_SPOT_URL + "/api/v3/exchangeInfo", params=params
143
+ )
144
+
145
+ async def depth(self, symbol: str, limit: int | None = None) -> dict:
146
+ """Получение стакана цен по торговой паре.
147
+
148
+ https://www.mexc.com/api-docs/spot-v3/market-data-endpoints#order-book
149
+ """
150
+ params = {
151
+ "symbol": symbol,
152
+ "limit": limit,
153
+ }
154
+
155
+ return await self._make_request("GET", self._BASE_SPOT_URL + "/api/v3/depth", params=params)
156
+
157
+ async def trades(self, symbol: str, limit: int | None = None) -> list[dict]:
158
+ """Получение списка последних сделок.
159
+
160
+ https://www.mexc.com/api-docs/spot-v3/market-data-endpoints#recent-trades-list
161
+ """
162
+ params = {
163
+ "symbol": symbol,
164
+ "limit": limit,
165
+ }
166
+
167
+ return await self._make_request(
168
+ "GET", self._BASE_SPOT_URL + "/api/v3/trades", params=params
169
+ )
170
+
171
+ async def agg_trades(
172
+ self,
173
+ symbol: str,
174
+ start_time: int | None = None,
175
+ end_time: int | None = None,
176
+ limit: int | None = None,
177
+ ) -> list[dict]:
178
+ """Получение агрегированных сделок по символу.
179
+
180
+ https://www.mexc.com/api-docs/spot-v3/market-data-endpoints#compressedaggregate-trades-list
181
+ """
182
+ params = {
183
+ "symbol": symbol,
184
+ "startTime": start_time,
185
+ "endTime": end_time,
186
+ "limit": limit,
187
+ }
188
+
189
+ return await self._make_request(
190
+ "GET", self._BASE_SPOT_URL + "/api/v3/aggTrades", params=params
191
+ )
192
+
193
+ async def klines(
194
+ self,
195
+ symbol: str,
196
+ interval: str,
197
+ start_time: int | None = None,
198
+ end_time: int | None = None,
199
+ limit: int | None = None,
200
+ ) -> list[list]:
201
+ """Получение свечных данных по торговой паре.
202
+
203
+ https://www.mexc.com/api-docs/spot-v3/market-data-endpoints#klinecandlestick-data
204
+ """
205
+ params = {
206
+ "symbol": symbol,
207
+ "interval": interval,
208
+ "startTime": start_time,
209
+ "endTime": end_time,
210
+ "limit": limit,
211
+ }
212
+
213
+ return await self._make_request(
214
+ "GET", self._BASE_SPOT_URL + "/api/v3/klines", params=params
215
+ )
216
+
217
+ async def avg_price(self, symbol: str) -> dict:
218
+ """Получение средней цены символа за последние минуты.
219
+
220
+ https://www.mexc.com/api-docs/spot-v3/market-data-endpoints#current-average-price
221
+ """
222
+ params = {"symbol": symbol}
223
+
224
+ return await self._make_request(
225
+ "GET", self._BASE_SPOT_URL + "/api/v3/avgPrice", params=params
226
+ )
227
+
228
+ async def ticker_24hr(self, symbol: str | None = None) -> dict | list[dict]:
229
+ """Получение статистики изменения цены за 24 часа.
230
+
231
+ https://www.mexc.com/api-docs/spot-v3/market-data-endpoints#24hr-ticker-price-change-statistics
232
+ """
233
+ params = {"symbol": symbol}
234
+
235
+ return await self._make_request(
236
+ "GET", self._BASE_SPOT_URL + "/api/v3/ticker/24hr", params=params
237
+ )
238
+
239
+ async def ticker_price(self, symbol: str | None = None) -> dict | list[dict]:
240
+ """Получение текущей цены символа.
241
+
242
+ https://www.mexc.com/api-docs/spot-v3/market-data-endpoints#symbol-price-ticker
243
+ """
244
+ params = {"symbol": symbol}
245
+
246
+ return await self._make_request(
247
+ "GET", self._BASE_SPOT_URL + "/api/v3/ticker/price", params=params
248
+ )
249
+
250
+ async def ticker_book_ticker(self, symbol: str | None = None) -> dict | list[dict]:
251
+ """Получение лучших цен и объемов в стакане.
252
+
253
+ https://www.mexc.com/api-docs/spot-v3/market-data-endpoints#symbol-order-book-ticker
254
+ """
255
+ params = {"symbol": symbol}
256
+
257
+ return await self._make_request(
258
+ "GET", self._BASE_SPOT_URL + "/api/v3/ticker/bookTicker", params=params
259
+ )
260
+
261
+ # topic: Spot Account/Trade
262
+ async def kyc_status(self) -> dict:
263
+ """Получение статуса верификации KYC.
264
+
265
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#query-kyc-status
266
+ """
267
+ return await self._make_request(
268
+ "GET", self._BASE_SPOT_URL + "/api/v3/kyc/status", signed=True
269
+ )
270
+
271
+ async def uid(self) -> dict:
272
+ """Получение UID аккаунта.
273
+
274
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#query-uid
275
+ """
276
+ return await self._make_request("GET", self._BASE_SPOT_URL + "/api/v3/uid", signed=True)
277
+
278
+ async def self_symbols(self) -> dict:
279
+ """Получение списка торговых пар, доступных через API аккаунта.
280
+
281
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#user-api-default-symbol
282
+ """
283
+ return await self._make_request(
284
+ "GET", self._BASE_SPOT_URL + "/api/v3/selfSymbols", signed=True
285
+ )
286
+
287
+ async def test_order(
288
+ self,
289
+ symbol: str,
290
+ side: str,
291
+ type: str,
292
+ quantity: str | None = None,
293
+ quote_order_quantity: str | None = None,
294
+ price: str | None = None,
295
+ new_client_order_id: str | None = None,
296
+ stp_mode: str | None = None,
297
+ ) -> dict:
298
+ """Проверка создания нового ордера без отправки на биржу.
299
+
300
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#test-new-order
301
+ """
302
+ params = {
303
+ "symbol": symbol,
304
+ "side": side,
305
+ "type": type,
306
+ "quantity": quantity,
307
+ "quoteOrderQty": quote_order_quantity,
308
+ "price": price,
309
+ "newClientOrderId": new_client_order_id,
310
+ "stpMode": stp_mode,
311
+ }
312
+
313
+ return await self._make_request(
314
+ "POST", self._BASE_SPOT_URL + "/api/v3/order/test", params=params, signed=True
315
+ )
316
+
317
+ async def create_order(
318
+ self,
319
+ symbol: str,
320
+ side: str,
321
+ type: str,
322
+ quantity: str | None = None,
323
+ quote_order_quantity: str | None = None,
324
+ price: str | None = None,
325
+ new_client_order_id: str | None = None,
326
+ stp_mode: str | None = None,
327
+ ) -> dict:
328
+ """Создание нового ордера.
329
+
330
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#new-order
331
+ """
332
+ params = {
333
+ "symbol": symbol,
334
+ "side": side,
335
+ "type": type,
336
+ "quantity": quantity,
337
+ "quoteOrderQty": quote_order_quantity,
338
+ "price": price,
339
+ "newClientOrderId": new_client_order_id,
340
+ "stpMode": stp_mode,
341
+ }
342
+
343
+ return await self._make_request(
344
+ "POST", self._BASE_SPOT_URL + "/api/v3/order", params=params, signed=True
345
+ )
346
+
347
+ async def batch_orders(self, batch_orders: list[dict]) -> dict | list[dict]:
348
+ """Создание нескольких ордеров одновременно.
349
+
350
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#batch-orders
351
+ """
352
+ params = {"batchOrders": batch_orders}
353
+
354
+ return await self._make_request(
355
+ "POST", self._BASE_SPOT_URL + "/api/v3/batchOrders", params=params, signed=True
356
+ )
357
+
358
+ async def cancel_order(
359
+ self,
360
+ symbol: str,
361
+ order_id: str | None = None,
362
+ orig_client_order_id: str | None = None,
363
+ new_client_order_id: str | None = None,
364
+ ) -> dict:
365
+ """Отмена активного ордера.
366
+
367
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#cancel-order
368
+ """
369
+ params = {
370
+ "symbol": symbol,
371
+ "orderId": order_id,
372
+ "origClientOrderId": orig_client_order_id,
373
+ "newClientOrderId": new_client_order_id,
374
+ }
375
+
376
+ return await self._make_request(
377
+ "DELETE", self._BASE_SPOT_URL + "/api/v3/order", params=params, signed=True
378
+ )
379
+
380
+ async def cancel_open_orders(self, symbol: str | list[str]) -> list[dict]:
381
+ """Отмена всех открытых ордеров по символу.
382
+
383
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#cancel-all-open-orders-on-a-symbol
384
+ """
385
+ params = {"symbol": symbol}
386
+
387
+ return await self._make_request(
388
+ "DELETE", self._BASE_SPOT_URL + "/api/v3/openOrders", params=params, signed=True
389
+ )
390
+
391
+ async def query_order(
392
+ self,
393
+ symbol: str,
394
+ order_id: str | None = None,
395
+ orig_client_order_id: str | None = None,
396
+ ) -> dict:
397
+ """Получение информации об ордере.
398
+
399
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#query-order
400
+ """
401
+ params = {
402
+ "symbol": symbol,
403
+ "orderId": order_id,
404
+ "origClientOrderId": orig_client_order_id,
405
+ }
406
+
407
+ return await self._make_request(
408
+ "GET", self._BASE_SPOT_URL + "/api/v3/order", params=params, signed=True
409
+ )
410
+
411
+ async def open_orders(self, symbol: str | None = None) -> list[dict]:
412
+ """Получение списка открытых ордеров.
413
+
414
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#current-open-orders
415
+ """
416
+ params = {"symbol": symbol}
417
+
418
+ return await self._make_request(
419
+ "GET", self._BASE_SPOT_URL + "/api/v3/openOrders", params=params, signed=True
420
+ )
421
+
422
+ async def all_orders(
423
+ self,
424
+ symbol: str,
425
+ start_time: int | None = None,
426
+ end_time: int | None = None,
427
+ limit: int | None = None,
428
+ ) -> list[dict]:
429
+ """Получение списка всех ордеров аккаунта по символу.
430
+
431
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#all-orders
432
+ """
433
+ params = {
434
+ "symbol": symbol,
435
+ "startTime": start_time,
436
+ "endTime": end_time,
437
+ "limit": limit,
438
+ }
439
+
440
+ return await self._make_request(
441
+ "GET", self._BASE_SPOT_URL + "/api/v3/allOrders", params=params, signed=True
442
+ )
443
+
444
+ async def account(self) -> dict:
445
+ """Получение информации об аккаунте.
446
+
447
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#account-information
448
+ """
449
+ return await self._make_request("GET", self._BASE_SPOT_URL + "/api/v3/account", signed=True)
450
+
451
+ async def my_trades(
452
+ self,
453
+ symbol: str,
454
+ order_id: str | None = None,
455
+ start_time: int | None = None,
456
+ end_time: int | None = None,
457
+ limit: int | None = None,
458
+ ) -> list[dict]:
459
+ """Получение списка сделок аккаунта по символу.
460
+
461
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#account-trade-list
462
+ """
463
+ params = {
464
+ "symbol": symbol,
465
+ "orderId": order_id,
466
+ "startTime": start_time,
467
+ "endTime": end_time,
468
+ "limit": limit,
469
+ }
470
+
471
+ return await self._make_request(
472
+ "GET", self._BASE_SPOT_URL + "/api/v3/myTrades", params=params, signed=True
473
+ )
474
+
475
+ async def enable_mx_deduct(self, mx_deduct_enable: bool) -> dict:
476
+ """Включение или отключение списания комиссий в MX.
477
+
478
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#enable-mx-deduct
479
+ """
480
+ params = {"mxDeductEnable": mx_deduct_enable}
481
+
482
+ return await self._make_request(
483
+ "POST", self._BASE_SPOT_URL + "/api/v3/mxDeduct/enable", params=params, signed=True
484
+ )
485
+
486
+ async def mx_deduct_status(self) -> dict:
487
+ """Получение статуса списания комиссий в MX.
488
+
489
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#query-mx-deduct-status
490
+ """
491
+ return await self._make_request(
492
+ "GET", self._BASE_SPOT_URL + "/api/v3/mxDeduct/enable", signed=True
493
+ )
494
+
495
+ async def trade_fee(self, symbol: str) -> dict:
496
+ """Получение комиссий по символу.
497
+
498
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#query-symbol-commission
499
+ """
500
+ params = {"symbol": symbol}
501
+
502
+ return await self._make_request(
503
+ "GET", self._BASE_SPOT_URL + "/api/v3/tradeFee", params=params, signed=True
504
+ )
505
+
506
+ async def create_strategy_group(self, trade_group_name: str) -> dict:
507
+ """Создание стратегии STP.
508
+
509
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#create-stp-strategy-group
510
+ """
511
+ params = {"tradeGroupName": trade_group_name}
512
+
513
+ return await self._make_request(
514
+ "POST", self._BASE_SPOT_URL + "/api/v3/strategy/group", params=params, signed=True
515
+ )
516
+
517
+ async def strategy_group(self, trade_group_name: str) -> dict:
518
+ """Получение информации о стратегии STP.
519
+
520
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#query-stp-strategy-group
521
+ """
522
+ params = {"tradeGroupName": trade_group_name}
523
+
524
+ return await self._make_request(
525
+ "GET", self._BASE_SPOT_URL + "/api/v3/strategy/group", params=params, signed=True
526
+ )
527
+
528
+ async def delete_strategy_group(self, trade_group_id: str) -> dict:
529
+ """Удаление стратегии STP.
530
+
531
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#delete-stp-strategy-group
532
+ """
533
+ params = {"tradeGroupId": trade_group_id}
534
+
535
+ return await self._make_request(
536
+ "DELETE", self._BASE_SPOT_URL + "/api/v3/strategy/group", params=params, signed=True
537
+ )
538
+
539
+ async def add_strategy_group_uid(self, uid: str | list[str], trade_group_id: str) -> dict:
540
+ """Добавление UID в стратегию STP.
541
+
542
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#add-uid-to-stp-strategy-group
543
+ """
544
+ params = {
545
+ "uid": uid,
546
+ "tradeGroupId": trade_group_id,
547
+ }
548
+
549
+ return await self._make_request(
550
+ "POST", self._BASE_SPOT_URL + "/api/v3/strategy/group/uid", params=params, signed=True
551
+ )
552
+
553
+ async def delete_strategy_group_uid(self, uid: str | list[str], trade_group_id: str) -> dict:
554
+ """Удаление UID из стратегии STP.
555
+
556
+ https://www.mexc.com/api-docs/spot-v3/spot-account-trade#delete-uid-to-stp-strategy-group
557
+ """
558
+ params = {
559
+ "uid": uid,
560
+ "tradeGroupId": trade_group_id,
561
+ }
562
+
563
+ return await self._make_request(
564
+ "DELETE", self._BASE_SPOT_URL + "/api/v3/strategy/group/uid", params=params, signed=True
565
+ )
566
+
567
+ # topic: Websocket User Data Streams
568
+
569
+ async def create_listen_key(self) -> dict:
570
+ """Создание listen key для пользовательского вебсокета.
571
+
572
+ https://www.mexc.com/api-docs/spot-v3/websocket-user-data-streams#generate-listen-key
573
+ """
574
+ return await self._make_request(
575
+ "POST", self._BASE_SPOT_URL + "/api/v3/userDataStream", signed=True
576
+ )
577
+
578
+ async def listen_keys(self) -> dict:
579
+ """Получение списка актуальных listen key.
580
+
581
+ https://www.mexc.com/api-docs/spot-v3/websocket-user-data-streams#get-valid-listen-keys
582
+ """
583
+ return await self._make_request(
584
+ "GET", self._BASE_SPOT_URL + "/api/v3/userDataStream", signed=True
585
+ )
586
+
587
+ async def renew_listen_key(self, listen_key: str) -> dict:
588
+ """Продление срока действия listen key.
589
+
590
+ https://www.mexc.com/api-docs/spot-v3/websocket-user-data-streams#extend-listen-key-validity
591
+ """
592
+ params = {"listenKey": listen_key}
593
+
594
+ return await self._make_request(
595
+ "PUT", self._BASE_SPOT_URL + "/api/v3/userDataStream", params=params, signed=True
596
+ )
597
+
598
+ async def close_listen_key(self, listen_key: str) -> dict:
599
+ """Закрытие listen key для пользовательского вебсокета.
600
+
601
+ https://www.mexc.com/api-docs/spot-v3/websocket-user-data-streams#close-listen-key
602
+ """
603
+ params = {"listenKey": listen_key}
604
+
605
+ return await self._make_request(
606
+ "DELETE", self._BASE_SPOT_URL + "/api/v3/userDataStream", params=params, signed=True
607
+ )
608
+
609
+ # topic: Futures Market endpoints
610
+
611
+ async def futures_server_time(self) -> dict:
612
+ """Получение текущего серверного времени фьючерсного API.
613
+
614
+ https://www.mexc.com/api-docs/futures/market-endpoints
615
+ """
616
+ return await self._make_request("GET", self._BASE_FUTURES_URL + "/api/v1/contract/ping")
617
+
618
+ async def futures_contract_detail(self, symbol: str | None = None) -> dict:
619
+ """Получение информации о фьючерсных контрактах.
620
+
621
+ https://www.mexc.com/api-docs/futures/market-endpoints
622
+ """
623
+ params = {"symbol": symbol}
624
+
625
+ return await self._make_request(
626
+ "GET", self._BASE_FUTURES_URL + "/api/v1/contract/detail", params=params
627
+ )
628
+
629
+ async def futures_support_currencies(self) -> dict:
630
+ """Получение списка поддерживаемых для перевода валют.
631
+
632
+ https://www.mexc.com/api-docs/futures/market-endpoints
633
+ """
634
+ return await self._make_request(
635
+ "GET", self._BASE_FUTURES_URL + "/api/v1/contract/support_currencies"
636
+ )
637
+
638
+ async def futures_depth(self, symbol: str, limit: int | None = None) -> dict:
639
+ """Получение данных рыночного стакана по контракту.
640
+
641
+ https://www.mexc.com/api-docs/futures/market-endpoints
642
+ """
643
+ params = {"limit": limit}
644
+
645
+ return await self._make_request(
646
+ "GET", self._BASE_FUTURES_URL + f"/api/v1/contract/depth/{symbol}", params=params
647
+ )
648
+
649
+ async def futures_depth_commits(self, symbol: str, limit: int) -> dict:
650
+ """Получение моментального снимка стакана по контракту.
651
+
652
+ https://www.mexc.com/api-docs/futures/market-endpoints
653
+ """
654
+ return await self._make_request(
655
+ "GET",
656
+ self._BASE_FUTURES_URL + f"/api/v1/contract/depth_commits/{symbol}/{limit}",
657
+ )
658
+
659
+ async def futures_index_price(self, symbol: str) -> dict:
660
+ """Получение индикативной цены контракта.
661
+
662
+ https://www.mexc.com/api-docs/futures/market-endpoints
663
+ """
664
+ return await self._make_request(
665
+ "GET", self._BASE_FUTURES_URL + f"/api/v1/contract/index_price/{symbol}"
666
+ )
667
+
668
+ async def futures_fair_price(self, symbol: str) -> dict:
669
+ """Получение справедливой цены контракта.
670
+
671
+ https://www.mexc.com/api-docs/futures/market-endpoints
672
+ """
673
+ return await self._make_request(
674
+ "GET", self._BASE_FUTURES_URL + f"/api/v1/contract/fair_price/{symbol}"
675
+ )
676
+
677
+ async def futures_funding_rate(self, symbol: str) -> dict:
678
+ """Получение текущей ставки финансирования контракта.
679
+
680
+ https://www.mexc.com/api-docs/futures/market-endpoints
681
+ """
682
+ return await self._make_request(
683
+ "GET", self._BASE_FUTURES_URL + f"/api/v1/contract/funding_rate/{symbol}"
684
+ )
685
+
686
+ async def futures_kline(
687
+ self,
688
+ symbol: str,
689
+ interval: str | None = None,
690
+ start: int | None = None,
691
+ end: int | None = None,
692
+ ) -> dict:
693
+ """Получение свечных данных по контракту.
694
+
695
+ https://www.mexc.com/api-docs/futures/market-endpoints#k-line-data
696
+ """
697
+ params = {
698
+ "interval": interval,
699
+ "start": start,
700
+ "end": end,
701
+ }
702
+
703
+ return await self._make_request(
704
+ "GET", self._BASE_FUTURES_URL + f"/api/v1/contract/kline/{symbol}", params=params
705
+ )
706
+
707
+ async def futures_index_price_kline(
708
+ self,
709
+ symbol: str,
710
+ interval: str | None = None,
711
+ start: int | None = None,
712
+ end: int | None = None,
713
+ ) -> dict:
714
+ """Получение свечей индикативной цены контракта.
715
+
716
+ https://www.mexc.com/api-docs/futures/market-endpoints
717
+ """
718
+ params = {
719
+ "interval": interval,
720
+ "start": start,
721
+ "end": end,
722
+ }
723
+
724
+ return await self._make_request(
725
+ "GET",
726
+ self._BASE_FUTURES_URL + f"/api/v1/contract/kline/index_price/{symbol}",
727
+ params=params,
728
+ )
729
+
730
+ async def futures_fair_price_kline(
731
+ self,
732
+ symbol: str,
733
+ interval: str | None = None,
734
+ start: int | None = None,
735
+ end: int | None = None,
736
+ ) -> dict:
737
+ """Получение свечей справедливой цены контракта.
738
+
739
+ https://www.mexc.com/api-docs/futures/market-endpoints
740
+ """
741
+ params = {
742
+ "interval": interval,
743
+ "start": start,
744
+ "end": end,
745
+ }
746
+
747
+ return await self._make_request(
748
+ "GET",
749
+ self._BASE_FUTURES_URL + f"/api/v1/contract/kline/fair_price/{symbol}",
750
+ params=params,
751
+ )
752
+
753
+ async def futures_deals(self, symbol: str, limit: int | None = None) -> dict:
754
+ """Получение последних сделок по контракту.
755
+
756
+ https://www.mexc.com/api-docs/futures/market-endpoints
757
+ """
758
+ params = {"limit": limit}
759
+
760
+ return await self._make_request(
761
+ "GET", self._BASE_FUTURES_URL + f"/api/v1/contract/deals/{symbol}", params=params
762
+ )
763
+
764
+ async def futures_ticker(self, symbol: str | None = None) -> dict:
765
+ """Получение текущих параметров тренда по контракту.
766
+
767
+ https://www.mexc.com/api-docs/futures/market-endpoints#get-contract-trend-data
768
+ """
769
+ params = {"symbol": symbol}
770
+
771
+ return await self._make_request(
772
+ "GET", self._BASE_FUTURES_URL + "/api/v1/contract/ticker", params=params
773
+ )
774
+
775
+ async def futures_risk_reverse(self) -> dict:
776
+ """Получение текущих балансов страхового фонда.
777
+
778
+ https://www.mexc.com/api-docs/futures/market-endpoints
779
+ """
780
+ return await self._make_request(
781
+ "GET", self._BASE_FUTURES_URL + "/api/v1/contract/risk_reverse"
782
+ )
783
+
784
+ async def futures_risk_reverse_history(
785
+ self,
786
+ symbol: str,
787
+ page_num: int,
788
+ page_size: int,
789
+ ) -> dict:
790
+ """Получение истории баланса страхового фонда по контракту.
791
+
792
+ https://www.mexc.com/api-docs/futures/market-endpoints
793
+ """
794
+ params = {
795
+ "symbol": symbol,
796
+ "page_num": page_num,
797
+ "page_size": page_size,
798
+ }
799
+
800
+ return await self._make_request(
801
+ "GET", self._BASE_FUTURES_URL + "/api/v1/contract/risk_reverse/history", params=params
802
+ )
803
+
804
+ async def futures_funding_rate_history(
805
+ self,
806
+ symbol: str,
807
+ page_num: int,
808
+ page_size: int,
809
+ ) -> dict:
810
+ """Получение истории ставок финансирования по контракту.
811
+
812
+ https://www.mexc.com/api-docs/futures/market-endpoints
813
+ """
814
+ params = {
815
+ "symbol": symbol,
816
+ "page_num": page_num,
817
+ "page_size": page_size,
818
+ }
819
+
820
+ return await self._make_request(
821
+ "GET", self._BASE_FUTURES_URL + "/api/v1/contract/funding_rate/history", params=params
822
+ )
823
+
824
+ # topic: Futures Account and trading endpoints
825
+
826
+ async def futures_account_assets(self) -> dict:
827
+ """Получение сведений по всем валютам фьючерсного аккаунта.
828
+
829
+ https://www.mexc.com/api-docs/futures/account-and-trading-endpoints
830
+ """
831
+ return await self._make_request(
832
+ "GET",
833
+ self._BASE_FUTURES_URL + "/api/v1/private/account/assets",
834
+ signed=True,
835
+ )
836
+
837
+ async def futures_account_asset(self, currency: str) -> dict:
838
+ """Получение баланса по одной валюте фьючерсного аккаунта.
839
+
840
+ https://www.mexc.com/api-docs/futures/account-and-trading-endpoints
841
+ """
842
+ return await self._make_request(
843
+ "GET",
844
+ self._BASE_FUTURES_URL + f"/api/v1/private/account/asset/{currency}",
845
+ signed=True,
846
+ )