unicex 0.13.5__py3-none-any.whl → 0.13.7__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.
unicex/_base/websocket.py CHANGED
@@ -179,18 +179,25 @@ class Websocket:
179
179
 
180
180
  async def _after_disconnect(self) -> None:
181
181
  """Вызывается после отключения от вебсокета."""
182
- # Останавливаем воркеров
182
+ current_task = asyncio.current_task()
183
+
184
+ # Останавливаем воркеров, исключая задачу, которая уже выполняет остановку
185
+ tasks_to_wait: list[asyncio.Task] = []
183
186
  for task in self._tasks:
187
+ if task is current_task:
188
+ continue
189
+
184
190
  task.cancel()
191
+ tasks_to_wait.append(task)
185
192
 
186
193
  # Дожидаемся завершения задач (в т.ч. воркеров)
187
- for task in self._tasks:
188
- try:
189
- await task
190
- except asyncio.CancelledError:
191
- pass
192
- except Exception as e:
193
- self._logger.warning(f"Worker raised during shutdown: {e}")
194
+ if tasks_to_wait:
195
+ results = await asyncio.gather(*tasks_to_wait, return_exceptions=True)
196
+ for task_result in results:
197
+ if isinstance(task_result, asyncio.CancelledError):
198
+ continue
199
+ if isinstance(task_result, Exception):
200
+ self._logger.warning(f"Worker raised during shutdown: {task_result}")
194
201
 
195
202
  self._tasks.clear()
196
203
 
@@ -99,24 +99,38 @@ class WebsocketManager:
99
99
  **self._ws_kwargs,
100
100
  )
101
101
 
102
- def candle(self, callback: CallbackType, coin: str, interval: str) -> Websocket:
102
+ def candle(
103
+ self,
104
+ callback: CallbackType,
105
+ interval: str,
106
+ coin: str | None = None,
107
+ coins: list[str] | None = None,
108
+ ) -> Websocket:
103
109
  """Создает вебсокет для получения свечей.
104
110
 
105
111
  Параметры:
106
112
  callback (`CallbackType`): Асинхронная функция обратного вызова для обработки сообщений.
107
113
  coin (`str`): Символ монеты.
114
+ coins (`list[str]`): Список символов монет для мультиплекс подключения.
108
115
  interval (`str`): Интервал свечей ("1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "8h", "12h", "1d", "3d", "1w", "1M").
109
116
 
110
117
  Возвращает:
111
118
  `Websocket`: Объект для управления вебсокет соединением.
112
119
  """
113
- subscription_message = self._create_subscription_message(
114
- "candle", coin=coin, interval=interval
115
- )
120
+ if coin and coins:
121
+ raise ValueError("Parameters coin and coins cannot be used together")
122
+ if not (coin or coins):
123
+ raise ValueError("Either coin or coins must be provided")
124
+ if coin:
125
+ coins = [coin]
126
+ subscription_messages = [
127
+ self._create_subscription_message("candle", coin=coin, interval=interval)
128
+ for coin in coins # type: ignore
129
+ ]
116
130
  return Websocket(
117
131
  callback=callback,
118
132
  url=self._URL,
119
- subscription_messages=[subscription_message],
133
+ subscription_messages=subscription_messages,
120
134
  **self._ws_kwargs,
121
135
  )
122
136
 
@@ -152,21 +166,33 @@ class WebsocketManager:
152
166
  **self._ws_kwargs,
153
167
  )
154
168
 
155
- def trades(self, callback: CallbackType, coin: str) -> Websocket:
169
+ def trades(
170
+ self, callback: CallbackType, coin: str | None = None, coins: list[str] | None = None
171
+ ) -> Websocket:
156
172
  """Создает вебсокет для получения сделок.
157
173
 
158
174
  Параметры:
159
175
  callback (`CallbackType`): Асинхронная функция обратного вызова для обработки сообщений.
160
- coin (`str`): Символ монеты.
176
+ coin (`str | None`): Символ монеты.
177
+ coins (`list[str] | None`): Список символов монет для мультиплекс подключения.
161
178
 
162
179
  Возвращает:
163
180
  `Websocket`: Объект для управления вебсокет соединением.
164
181
  """
165
- subscription_message = self._create_subscription_message("trades", coin=coin)
182
+ if coin and coins:
183
+ raise ValueError("Parameters coin and coins cannot be used together")
184
+ if not (coin or coins):
185
+ raise ValueError("Either coin or coins must be provided")
186
+ if coin:
187
+ coins = [coin]
188
+ subscription_messages = [
189
+ self._create_subscription_message("trades", coin=coin)
190
+ for coin in coins # type: ignore
191
+ ]
166
192
  return Websocket(
167
193
  callback=callback,
168
194
  url=self._URL,
169
- subscription_messages=[subscription_message],
195
+ subscription_messages=subscription_messages,
170
196
  **self._ws_kwargs,
171
197
  )
172
198
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unicex
3
- Version: 0.13.5
3
+ Version: 0.13.7
4
4
  Summary: Unified Crypto Exchange API
5
5
  Author-email: LoveBloodAndDiamonds <ayazshakirzyanov27@gmail.com>
6
6
  License: BSD 3-Clause License
@@ -11,7 +11,7 @@ unicex/_abc/uni_client.py,sha256=ZjxK8aqCGLUUYy1UQTM9EvWn1IXwMkH2Db8sZrs1e_I,137
11
11
  unicex/_abc/uni_websocket_manager.py,sha256=yYKypPkIe3rKfWBuTsS8rkwIPljpd1588CYDkeTOYqE,9905
12
12
  unicex/_base/__init__.py,sha256=0TmevATGnRB3qow6tkCR8dQKNZCWKeib6YQjNJ4a1b0,236
13
13
  unicex/_base/client.py,sha256=asIIQLZlRwwmUDvxveSv7aCvth54iiSRJdz19bxGorI,8904
14
- unicex/_base/websocket.py,sha256=Q7kbBEOAlPHL8S3y1KZmQghxMGq4hkjZ3ZepZqm47oA,12115
14
+ unicex/_base/websocket.py,sha256=haSV3dSgkT352n8knpLm_iI4ZlUGWWKFCB3k5Ua2esU,12542
15
15
  unicex/binance/__init__.py,sha256=sDk4ZjakRdpFMaMSpOCfqjf6ZPfAS9tlrt4WlDHtDkw,932
16
16
  unicex/binance/adapter.py,sha256=JbUFyjnDAFtyuYYrh90YeOvQOZQ6faim0nWS6U0NxXw,8799
17
17
  unicex/binance/client.py,sha256=1qPx0uRT4prC6saLBQ55pXDWcWTCKhYEwVIysiihPgU,60984
@@ -51,7 +51,7 @@ unicex/hyperliquid/exchange_info.py,sha256=D1h1fvH9DycRq-xDTZ_-Y1NC2JCp165IyWMXs
51
51
  unicex/hyperliquid/uni_client.py,sha256=4jv2uC076PBeq-EzCKvwaEEMk_M3HpsWA6iwNepJg7E,15674
52
52
  unicex/hyperliquid/uni_websocket_manager.py,sha256=AzR_8Aq98NkCA1oc2IiH02ysMOYLaisEmcuuaafeaJw,9334
53
53
  unicex/hyperliquid/user_websocket.py,sha256=BKD9ap2bx5DwpkkwwecfOTVedrZBR9eMAITgCBgg02w,134
54
- unicex/hyperliquid/websocket_manager.py,sha256=GNBQT4ihk1XsTAaas8lxAfo3ASBGs_8EVrSR1_N9D-U,16820
54
+ unicex/hyperliquid/websocket_manager.py,sha256=7z_P2I4YHJ91nfn--CX7VB2QX9A__imL4ca5Tt0Wld8,17871
55
55
  unicex/mexc/__init__.py,sha256=lltANqM_2P-fmF5j8o5-pjmORPuK6C5sVjcQhuUU_R0,923
56
56
  unicex/mexc/adapter.py,sha256=uaJ6157wTrMuf72thIggDJHiaeRVYyH0qMIn1x5Mrp8,9820
57
57
  unicex/mexc/client.py,sha256=oJSpz-8hvA1WMCN2B7oqI2lXEx1_VJLAn8jbzhW8mF0,30950
@@ -86,8 +86,8 @@ unicex/okx/uni_client.py,sha256=E_Wod0JSGt1K6k1mAIWnOv350pELbv-nic7g1KgOuos,8694
86
86
  unicex/okx/uni_websocket_manager.py,sha256=b4f_QjA64DJmENQdIGb5IOVc7kvit7KMCdWeCmRbxGY,9326
87
87
  unicex/okx/user_websocket.py,sha256=8c9kpm-xVa729pW93OKUGLHaE9MY0uzEpjIgNIFRF80,126
88
88
  unicex/okx/websocket_manager.py,sha256=wROXTUDqKzOE-wDnCtXso_MC4SzfPuPols5aPg_Z3y4,26027
89
- unicex-0.13.5.dist-info/licenses/LICENSE,sha256=lNNK4Vqak9cXm6qVJLhbqS7iR_BMj6k7fd7XQ6l1k54,1507
90
- unicex-0.13.5.dist-info/METADATA,sha256=faWjzNhcaHx7lkzBFI-SSmH_35Dd1pGumzi87UCtMNQ,11752
91
- unicex-0.13.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
92
- unicex-0.13.5.dist-info/top_level.txt,sha256=_7rar-0OENIg4KRy6cgjWiebFYAJhjKEcMggAocGWG4,7
93
- unicex-0.13.5.dist-info/RECORD,,
89
+ unicex-0.13.7.dist-info/licenses/LICENSE,sha256=lNNK4Vqak9cXm6qVJLhbqS7iR_BMj6k7fd7XQ6l1k54,1507
90
+ unicex-0.13.7.dist-info/METADATA,sha256=s1fo3iBF1O5boIO2BF86NNvOXdhp0BAMoPO-JyzjqQA,11752
91
+ unicex-0.13.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
92
+ unicex-0.13.7.dist-info/top_level.txt,sha256=_7rar-0OENIg4KRy6cgjWiebFYAJhjKEcMggAocGWG4,7
93
+ unicex-0.13.7.dist-info/RECORD,,