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/adapter.py ADDED
@@ -0,0 +1,239 @@
1
+ __all__ = ["Adapter"]
2
+
3
+ from unicex.types import (
4
+ KlineDict,
5
+ OpenInterestDict,
6
+ OpenInterestItem,
7
+ TickerDailyDict,
8
+ TickerDailyItem,
9
+ )
10
+ from unicex.utils import catch_adapter_errors, decorate_all_methods
11
+
12
+ from .exchange_info import ExchangeInfo
13
+
14
+
15
+ @decorate_all_methods(catch_adapter_errors)
16
+ class Adapter:
17
+ """Адаптер для унификации данных с Mexc API."""
18
+
19
+ @staticmethod
20
+ def tickers(raw_data: list[dict], only_usdt: bool) -> list[str]:
21
+ """Преобразует сырой ответ, в котором содержатся данные о тикерах, в список тикеров.
22
+
23
+ Параметры:
24
+ raw_data (list[dict]): Сырой ответ с биржи.
25
+ only_usdt (bool): Флаг, указывающий, нужно ли включать только тикеры в паре к USDT.
26
+
27
+ Возвращает:
28
+ list[str]: Список тикеров.
29
+ """
30
+ return [
31
+ item["symbol"] for item in raw_data if item["symbol"].endswith("USDT") or not only_usdt
32
+ ]
33
+
34
+ @staticmethod
35
+ def futures_tickers(raw_data: dict, only_usdt: bool) -> list[str]:
36
+ """Преобразует сырой ответ, в котором содержатся данные о фьючерсных тикерах, в список тикеров.
37
+
38
+ Параметры:
39
+ raw_data (dict): Сырой ответ с биржи.
40
+ only_usdt (bool): Флаг, указывающий, нужно ли включать только тикеры в паре к USDT.
41
+
42
+ Возвращает:
43
+ list[str]: Список тикеров.
44
+ """
45
+ return [
46
+ item["symbol"]
47
+ for item in raw_data["data"]
48
+ if item["symbol"].endswith("USDT") or not only_usdt
49
+ ]
50
+
51
+ @staticmethod
52
+ def last_price(raw_data: list[dict]) -> dict[str, float]:
53
+ """Преобразует сырой ответ, в котором содержатся данные о спотовых ценах, в унифицированный формат.
54
+
55
+ Параметры:
56
+ raw_data (list[dict]): Сырой ответ с биржи.
57
+
58
+ Возвращает:
59
+ dict[str, float]: Словарь, где ключ - тикер, а значение - последняя цена.
60
+ """
61
+ return {item["symbol"]: float(item["lastPrice"]) for item in raw_data}
62
+
63
+ @staticmethod
64
+ def futures_last_price(raw_data: dict) -> dict[str, float]:
65
+ """Преобразует сырой ответ, в котором содержатся данные о фьючерсных ценах, в унифицированный формат.
66
+
67
+ Параметры:
68
+ raw_data (dict): Сырой ответ с биржи.
69
+
70
+ Возвращает:
71
+ dict[str, float]: Словарь, где ключ - тикер, а значение - последняя цена.
72
+ """
73
+ return {item["symbol"]: float(item["lastPrice"]) for item in raw_data["data"]}
74
+
75
+ @staticmethod
76
+ def ticker_24hr(raw_data: list[dict]) -> TickerDailyDict:
77
+ """Преобразует сырой ответ, в котором содержатся данные о статистике за 24 часа, в унифицированный формат.
78
+
79
+ Параметры:
80
+ raw_data (list[dict]): Сырой ответ с биржи.
81
+
82
+ Возвращает:
83
+ TickerDailyDict: Словарь, где ключ - тикер, а значение - статистика за последние 24 часа.
84
+ """
85
+ return {
86
+ item["symbol"]: TickerDailyItem(
87
+ p=round(float(item["priceChangePercent"]) * 100, 2), # Конвертируем в проценты
88
+ v=float(item["volume"]),
89
+ q=float(item["quoteVolume"]),
90
+ )
91
+ for item in raw_data
92
+ }
93
+
94
+ @staticmethod
95
+ def futures_ticker_24hr(raw_data: dict) -> TickerDailyDict:
96
+ """Преобразует сырой ответ, в котором содержатся данные о фьючерсной статистике за 24 часа, в унифицированный формат.
97
+
98
+ Параметры:
99
+ raw_data (dict): Сырой ответ с биржи.
100
+
101
+ Возвращает:
102
+ TickerDailyDict: Словарь, где ключ - тикер, а значение - статистика за последние 24 часа.
103
+ """
104
+ result = {}
105
+ for item in raw_data["data"]:
106
+ symbol = item["symbol"]
107
+ result[symbol] = TickerDailyItem(
108
+ p=round(float(item["riseFallRate"]) * 100, 2),
109
+ v=float(item["volume24"]) * Adapter._get_contract_size(symbol),
110
+ q=float(item["amount24"]),
111
+ )
112
+ return result
113
+
114
+ @staticmethod
115
+ def open_interest(raw_data: dict) -> OpenInterestDict:
116
+ """Преобразует сырой ответ, в котором содержатся данные об открытом интересе, в унифицированный формат.
117
+
118
+ Параметры:
119
+ raw_data (dict): Сырой ответ с биржи.
120
+
121
+ Возвращает:
122
+ OpenInterestDict: Словарь, где ключ - тикер, а значение - агрегированные данные открытого интереса.
123
+ """
124
+ result = {}
125
+ for item in raw_data["data"]:
126
+ symbol = item["symbol"]
127
+ result[symbol] = OpenInterestItem(
128
+ t=item["timestamp"],
129
+ v=float(item["holdVol"]) * Adapter._get_contract_size(symbol),
130
+ )
131
+ return result
132
+
133
+ @staticmethod
134
+ def funding_rate(raw_data: dict) -> dict[str, float]:
135
+ """Преобразует сырой ответ, в котором содержатся данные о ставках финансирования, в унифицированный формат.
136
+
137
+ Параметры:
138
+ raw_data (dict): Сырой ответ с биржи.
139
+
140
+ Возвращает:
141
+ dict[str, float]: Словарь, где ключ - тикер, а значение - ставка финансирования.
142
+ """
143
+ return {
144
+ item["symbol"]: float(item["fundingRate"]) * 100
145
+ for item in raw_data["data"]
146
+ if "fundingRate" in item # В некоторых элементах item нет ключа 'fundingRate'
147
+ }
148
+
149
+ @staticmethod
150
+ def klines(raw_data: list[list], symbol: str) -> list[KlineDict]:
151
+ """Преобразует сырой ответ, в котором содержатся данные о свечах, в унифицированный формат.
152
+
153
+ Параметры:
154
+ raw_data (list[list]): Сырой ответ с биржи.
155
+ symbol (str): Символ тикера.
156
+
157
+ Возвращает:
158
+ list[KlineDict]: Список словарей, где каждый словарь содержит данные о свече.
159
+ """
160
+ return [
161
+ KlineDict(
162
+ s=symbol,
163
+ t=kline[0],
164
+ o=float(kline[1]),
165
+ h=float(kline[2]),
166
+ l=float(kline[3]),
167
+ c=float(kline[4]),
168
+ v=float(kline[5]),
169
+ q=float(kline[7]),
170
+ T=kline[6],
171
+ x=None,
172
+ )
173
+ for kline in sorted(
174
+ raw_data,
175
+ key=lambda x: int(x[0]),
176
+ )
177
+ ]
178
+
179
+ @staticmethod
180
+ def futures_klines(raw_data: dict, symbol: str) -> list[KlineDict]:
181
+ """Преобразует сырой ответ, в котором содержатся данные о фьючерсных свечах, в унифицированный формат.
182
+
183
+ Параметры:
184
+ raw_data (dict): Сырой ответ с биржи.
185
+ symbol (str): Символ тикера.
186
+
187
+ Возвращает:
188
+ list[KlineDict]: Список словарей, где каждый словарь содержит данные о свече.
189
+ """
190
+ data = raw_data["data"]
191
+
192
+ times = data["time"]
193
+ opens = data["open"]
194
+ highs = data["high"]
195
+ lows = data["low"]
196
+ closes = data["close"]
197
+ volumes = data["vol"]
198
+ amounts = data["amount"]
199
+
200
+ klines: list[KlineDict] = []
201
+
202
+ for kline_time, open_, high, low, close, volume, amount in zip(
203
+ times,
204
+ opens,
205
+ highs,
206
+ lows,
207
+ closes,
208
+ volumes,
209
+ amounts,
210
+ strict=False,
211
+ ):
212
+ timestamp = int(float(kline_time))
213
+ if timestamp < 10**12:
214
+ timestamp *= 1000
215
+
216
+ klines.append(
217
+ KlineDict(
218
+ s=symbol,
219
+ t=timestamp,
220
+ o=float(open_),
221
+ h=float(high),
222
+ l=float(low),
223
+ c=float(close),
224
+ v=float(volume),
225
+ q=float(amount),
226
+ T=None,
227
+ x=None,
228
+ )
229
+ )
230
+
231
+ return sorted(klines, key=lambda kline_item: kline_item["t"])
232
+
233
+ @staticmethod
234
+ def _get_contract_size(symbol: str) -> float:
235
+ """Возвращает размер контракта для указанного символа тикера."""
236
+ try:
237
+ return ExchangeInfo.get_futures_ticker_info(symbol)["contract_size"] or 1
238
+ except: # noqa
239
+ return 1