unicex 0.1.15__py3-none-any.whl → 0.1.16__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.
@@ -1,6 +1,7 @@
1
1
  __all__ = ["BaseClient"]
2
2
 
3
3
  import asyncio
4
+ import json
4
5
  from itertools import cycle
5
6
  from typing import Any, Self
6
7
 
@@ -169,27 +170,45 @@ class BaseClient:
169
170
  Возвращает:
170
171
  `dict | list`: Ответ API в формате JSON.
171
172
  """
173
+ response_text = await response.text()
174
+ status_code = response.status
175
+
176
+ # Парсинг JSON
172
177
  try:
173
- response.raise_for_status()
174
- except Exception as e:
175
- response_text = await response.text()
178
+ response_json = json.loads(response_text)
179
+ except json.JSONDecodeError as e:
176
180
  raise ResponseError(
177
- f"HTTP error: {e}. Response: {response_text}. Status code: {response.status}"
178
- ) from e
181
+ f"JSONDecodeError: {e}. Response: {response_text}. Status code: {response.status}",
182
+ status_code=status_code,
183
+ response_text=response_text,
184
+ ) from None
179
185
 
186
+ # Проверка HTTP-статуса
180
187
  try:
181
- result = await response.json()
188
+ response.raise_for_status()
182
189
  except Exception as e:
190
+ error_code = next(
191
+ (
192
+ response_json[k]
193
+ for k in ("code", "err_code", "errCode", "status")
194
+ if k in response_json
195
+ ),
196
+ "",
197
+ )
183
198
  raise ResponseError(
184
- f"JSONDecodeError error: {e}. Response: {response.text}. Status code: {response.status}"
185
- ) from e
186
-
199
+ f"HTTP error: {e}. Response: {response_json}. Status code: {response.status}",
200
+ status_code=status_code,
201
+ code=error_code,
202
+ response_text=response_text,
203
+ response_json=response_json,
204
+ ) from None
205
+
206
+ # Логирование ответа
187
207
  try:
188
- result_str: str = str(result)
189
208
  self._logger.debug(
190
- f"Response: {result_str[:100]}{'...' if len(result_str) > 100 else ''}"
209
+ f"Response: {response_text[:300]}{'...' if len(response_text) > 300 else ''}"
191
210
  )
192
211
  except Exception as e:
193
- self._logger.error(f"Error while log response: {e}")
212
+ self._logger.error(f"Error while logging response: {e}")
194
213
 
195
- return result
214
+ return response_json
@@ -1,5 +1,6 @@
1
1
  __all__ = ["BaseClient"]
2
2
 
3
+ import json
3
4
  import time
4
5
  from itertools import cycle
5
6
  from typing import Any, Self
@@ -133,37 +134,53 @@ class BaseClient:
133
134
  ) from errors[-1]
134
135
 
135
136
  def _handle_response(self, response: requests.Response) -> Any:
136
- """Обрабатывает HTTP‑ответ.
137
+ """Обрабатывает HTTP-ответ.
137
138
 
138
139
  Параметры:
139
- response (`requests.Response`): Ответ HTTP‑запроса.
140
+ response (`requests.Response`): Ответ HTTP-запроса.
140
141
 
141
142
  Возвращает:
142
143
  `dict | list`: Ответ API в формате JSON.
143
144
  """
145
+ response_text = response.text
146
+ status_code = response.status_code
147
+
148
+ # Парсинг JSON
144
149
  try:
145
- response.raise_for_status()
146
- except Exception as e:
150
+ response_json = json.loads(response_text)
151
+ except json.JSONDecodeError as e:
147
152
  raise ResponseError(
148
- f"HTTP error: {e}. Response: {response.text}. Status code: {response.status_code}"
149
- ) from e
150
-
151
- if not response.content:
152
- raise ResponseError(f"Empty response. Status code: {response.status_code}")
153
+ f"JSONDecodeError: {e}. Response: {response_text}. Status code: {status_code}",
154
+ status_code=status_code,
155
+ response_text=response_text,
156
+ ) from None
153
157
 
158
+ # Проверка HTTP-статуса
154
159
  try:
155
- result = response.json()
156
- except requests.exceptions.JSONDecodeError as e:
160
+ response.raise_for_status()
161
+ except Exception as e:
162
+ error_code = next(
163
+ (
164
+ response_json[k]
165
+ for k in ("code", "err_code", "errCode", "status")
166
+ if k in response_json
167
+ ),
168
+ "",
169
+ )
157
170
  raise ResponseError(
158
- f"JSONDecodeError error: {e}. Response: {response.text}. Status code: {response.status_code}"
159
- ) from e
160
-
171
+ f"HTTP error: {e}. Response: {response_json}. Status code: {status_code}",
172
+ status_code=status_code,
173
+ code=error_code,
174
+ response_text=response_text,
175
+ response_json=response_json,
176
+ ) from None
177
+
178
+ # Логирование ответа
161
179
  try:
162
- result_str: str = str(result)
163
180
  self._logger.debug(
164
- f"Response: {result_str[:100]}{'...' if len(result_str) > 100 else ''}"
181
+ f"Response: {response_text[:300]}{'...' if len(response_text) > 300 else ''}"
165
182
  )
166
183
  except Exception as e:
167
- self._logger.error(f"Error while log response: {e}")
184
+ self._logger.error(f"Error while logging response: {e}")
168
185
 
169
- return result
186
+ return response_json
@@ -74,6 +74,7 @@ class ClientMixin:
74
74
  "ACCESS-PASSPHRASE": self._api_passphrase, # type: ignore[attr-defined]
75
75
  "ACCESS-TIMESTAMP": timestamp,
76
76
  "ACCESS-SIGN": signature,
77
+ "locale": "en-US",
77
78
  }
78
79
  )
79
80
  return headers
unicex/exceptions.py CHANGED
@@ -1,6 +1,6 @@
1
1
  """Модуль,который описывает исключения и ошибки, которые могут возникнуть при работе с библиотекой."""
2
2
 
3
- from dataclasses import dataclass
3
+ from dataclasses import dataclass, field
4
4
 
5
5
 
6
6
  @dataclass
@@ -43,4 +43,22 @@ class QueueOverflowError(UniCexException):
43
43
  class ResponseError(UniCexException):
44
44
  """Исключение, возникающее при ошибке ответа."""
45
45
 
46
- pass
46
+ status_code: int
47
+ code: str = "" # "" - means undefined
48
+ response_json: dict = field(default_factory=dict)
49
+ response_text: str = ""
50
+
51
+ def __str__(self) -> str:
52
+ """Возвращает строковое представление исключения."""
53
+ if self.response_json:
54
+ preview = str(self.response_json)
55
+ if len(preview) > 500:
56
+ preview = preview[:500] + "..."
57
+ return f"ResponseError: status_code={self.status_code}, code={self.code}, response_json: {preview}"
58
+ elif self.response_text:
59
+ preview = str(self.response_text)
60
+ if len(preview) > 500:
61
+ preview = preview[:500] + "..."
62
+ return f"ResponseError: status_code={self.status_code}, code={self.code}, response_text: {preview}"
63
+ else:
64
+ return f"ResponseError: status_code={self.status_code}, code={self.code}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unicex
3
- Version: 0.1.15
3
+ Version: 0.1.16
4
4
  Summary: Unified Crypto Exchange API
5
5
  Author-email: LoveBloodAndDiamonds <ayazshakirzyanov27@gmail.com>
6
6
  License: BSD 3-Clause License
@@ -1,6 +1,6 @@
1
1
  unicex/__init__.py,sha256=LkRQxl60i91NZqLEOgOquh60tK73M31WaorxMUsS4-k,1372
2
2
  unicex/enums.py,sha256=wce1tN1qUIbx2seOzLh64kr0c5qyfji4FW7Qf2Crzp4,4215
3
- unicex/exceptions.py,sha256=Sl-MkTq1WhmGZbkjm-Hwn3Bn5dDH5V1Sr5QD_iOsEZw,1289
3
+ unicex/exceptions.py,sha256=r-xZzX78VuxVnI5pe99AM8FIiGcdIUDcF5CaTkQ4NE0,2213
4
4
  unicex/extra.py,sha256=qgN0RH0g7V5Ve30bsYageiL3gAyxplU1wk7XLmzFXWo,6805
5
5
  unicex/mapper.py,sha256=Ymasn7zq5W0A1WEsIHO3st1FgeryvD7-ShWEi5kr9Mk,4658
6
6
  unicex/types.py,sha256=j74BbMxpraWg2Nncu6Fqtec0BPs_gRKiuIfR_A7DxEg,2171
@@ -15,10 +15,10 @@ unicex/_abc/sync/uni_client.py,sha256=ZKltLNHtinj1aepknk8Neh7EOPhJj0jHcBMkVHyG_a
15
15
  unicex/_abc/sync/uni_websocket_manager.py,sha256=MPGZfcC1FLcsRIvKj2yQHaK1nwSBo-KpSnIeuVcBE2c,9731
16
16
  unicex/_base/__init__.py,sha256=SMe2SLh94RNJbdI-w_CmaXA0479nCBJfbxOApKT5Iak,90
17
17
  unicex/_base/asyncio/__init__.py,sha256=ckqI6LVP3DHuIiLXKx67rJyG0SEEsPnBr8uk1Dw9cwg,114
18
- unicex/_base/asyncio/client.py,sha256=ba87j1vpku5O24a9wsYQgf776OGUX85soLgUChBCwss,8223
18
+ unicex/_base/asyncio/client.py,sha256=Na6yIOCvuQgLzLeO5fOtsxZ0M71UMcYXIJA4ADFqYyU,8894
19
19
  unicex/_base/asyncio/websocket.py,sha256=VANQYJKVv75t85dL1JePO77IbdsHC6h8d9_8jjwCh-4,10016
20
20
  unicex/_base/sync/__init__.py,sha256=ckqI6LVP3DHuIiLXKx67rJyG0SEEsPnBr8uk1Dw9cwg,114
21
- unicex/_base/sync/client.py,sha256=A-c-M4tXSlUX_4hlqjwL5zm_yjtRkAEqcqc3xw49T6A,6648
21
+ unicex/_base/sync/client.py,sha256=sYEJP-DHH4alWoFHbCvNWUH5WRvt3QYzC0Vyp5uQcgg,7202
22
22
  unicex/_base/sync/websocket.py,sha256=tSTmZZFkbtcI1FWME__AkiMjcu3xNaRA0a0HoAnhkE0,10156
23
23
  unicex/binance/__init__.py,sha256=prW16sT_wNyu2Cx9w2Dndsu-kW6qsy_Cs5qP2XMBljo,446
24
24
  unicex/binance/adapter.py,sha256=f20XKuXdaWTBkFAfLgFXIuQoJwL_56-WMASzunV4TKo,14305
@@ -43,7 +43,7 @@ unicex/bitget/__init__.py,sha256=C0H2WB8HZiRZKqKkF3_d09I5guqQpzj8sLbZDaS_-Gs,192
43
43
  unicex/bitget/adapter.py,sha256=eyyt1L_VnlW_l2tQ4Ymut4eyYqfdNzNV2MvX6V7g_mQ,11589
44
44
  unicex/bitget/types.py,sha256=m-QJdZYaD08XmGpY25eciOK7PRLI4KjheTn5MBR15Gk,2022
45
45
  unicex/bitget/_mixins/__init__.py,sha256=DUS9aZ2LeI4DOHUxFGwoB8s_45smA5KFpt5kQ7HAZ6c,148
46
- unicex/bitget/_mixins/client.py,sha256=lXmvLrcWT1v3XHNuHgfsxQ_3V-i0MtXLwMyPZ8Ya6Jg,5149
46
+ unicex/bitget/_mixins/client.py,sha256=mGwc4mLzyuub_UA9-7-cFzAltNFwXPSXpvempj9KB5I,5188
47
47
  unicex/bitget/_mixins/user_websocket.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
48
  unicex/bitget/_mixins/websocket_manager.py,sha256=JHuhJOYO0VtnIVSt34o3hfdjKTsYzJYovl9GRVwXJtM,1924
49
49
  unicex/bitget/asyncio/__init__.py,sha256=N798Z5m25xLz5x1yRhB0Y2UOYuJ0CAeNryM_OAHBqAk,242
@@ -59,8 +59,8 @@ unicex/bybit/types.py,sha256=gCuzL_casy9kYQ33Mc5hiFW4MjTiEEU7xva38PkkfRA,8016
59
59
  unicex/bybit/uni_client.py,sha256=x8e3m4IH-tDGyjNk4hnM7KBrZFkLglF-RI8AuIhKJjc,6908
60
60
  unicex/bybit/websocket.py,sha256=K48uwoF2wjy1McGGfmUGj1Q9s3DvSabNLViqgBAG9YQ,159
61
61
  unicex/bybit/websocket_manager.py,sha256=3FdZn7WPAFnKsnknjDvbDnbpgH8xMj_4v-ksW81c9d4,902
62
- unicex-0.1.15.dist-info/licenses/LICENSE,sha256=lNNK4Vqak9cXm6qVJLhbqS7iR_BMj6k7fd7XQ6l1k54,1507
63
- unicex-0.1.15.dist-info/METADATA,sha256=m8NzKbMLshLZBqBq1PSWm4PWBDiQ2g00HI9D5ksE5bI,7158
64
- unicex-0.1.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
65
- unicex-0.1.15.dist-info/top_level.txt,sha256=_7rar-0OENIg4KRy6cgjWiebFYAJhjKEcMggAocGWG4,7
66
- unicex-0.1.15.dist-info/RECORD,,
62
+ unicex-0.1.16.dist-info/licenses/LICENSE,sha256=lNNK4Vqak9cXm6qVJLhbqS7iR_BMj6k7fd7XQ6l1k54,1507
63
+ unicex-0.1.16.dist-info/METADATA,sha256=Rj2_mCThWnvqfrtIaVI8jeMAw5UrnnoUv4PDf2Q_5gI,7158
64
+ unicex-0.1.16.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
65
+ unicex-0.1.16.dist-info/top_level.txt,sha256=_7rar-0OENIg4KRy6cgjWiebFYAJhjKEcMggAocGWG4,7
66
+ unicex-0.1.16.dist-info/RECORD,,