trd-utils 0.0.26__tar.gz → 0.0.27__tar.gz
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.
Potentially problematic release.
This version of trd-utils might be problematic. Click here for more details.
- {trd_utils-0.0.26 → trd_utils-0.0.27}/PKG-INFO +1 -1
- {trd_utils-0.0.26 → trd_utils-0.0.27}/pyproject.toml +1 -1
- trd_utils-0.0.27/trd_utils/__init__.py +3 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/exchange_base.py +55 -9
- trd_utils-0.0.26/trd_utils/__init__.py +0 -3
- {trd_utils-0.0.26 → trd_utils-0.0.27}/LICENSE +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/README.md +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/cipher/__init__.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/common_utils/float_utils.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/common_utils/wallet_utils.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/date_utils/__init__.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/date_utils/datetime_helpers.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/README.md +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/__init__.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/base_types.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/blofin/__init__.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/blofin/blofin_client.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/blofin/blofin_types.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/bx_ultra/__init__.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/bx_ultra/bx_types.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/bx_ultra/bx_ultra_client.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/bx_ultra/bx_utils.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/hyperliquid/README.md +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/hyperliquid/__init__.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/hyperliquid/hyperliquid_client.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/hyperliquid/hyperliquid_types.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/okx/__init__.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/okx/okx_client.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/exchanges/okx/okx_types.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/html_utils/__init__.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/html_utils/html_formats.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/tradingview/__init__.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/tradingview/tradingview_client.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/tradingview/tradingview_types.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/types_helper/__init__.py +0 -0
- {trd_utils-0.0.26 → trd_utils-0.0.27}/trd_utils/types_helper/base_model.py +0 -0
|
@@ -82,13 +82,12 @@ class ExchangeBase(ABC):
|
|
|
82
82
|
headers=headers,
|
|
83
83
|
params=params,
|
|
84
84
|
)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return model_type.deserialize(response.json(parse_float=parse_float))
|
|
85
|
+
return self._handle_response(
|
|
86
|
+
response=response,
|
|
87
|
+
model_type=model_type,
|
|
88
|
+
parse_float=parse_float,
|
|
89
|
+
raw_data=raw_data,
|
|
90
|
+
)
|
|
92
91
|
|
|
93
92
|
async def invoke_post(
|
|
94
93
|
self,
|
|
@@ -113,14 +112,61 @@ class ExchangeBase(ABC):
|
|
|
113
112
|
params=params,
|
|
114
113
|
content=content,
|
|
115
114
|
)
|
|
115
|
+
return self._handle_response(
|
|
116
|
+
response=response,
|
|
117
|
+
model_type=model_type,
|
|
118
|
+
parse_float=parse_float,
|
|
119
|
+
raw_data=raw_data,
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
def _handle_response(
|
|
123
|
+
self,
|
|
124
|
+
response: httpx.Response,
|
|
125
|
+
model_type: Type[BaseModel] | None = None,
|
|
126
|
+
parse_float=Decimal,
|
|
127
|
+
raw_data: bool = False,
|
|
128
|
+
) -> "BaseModel":
|
|
116
129
|
if raw_data:
|
|
117
130
|
return response.content
|
|
118
131
|
|
|
132
|
+
j_obj = self._resp_to_json(
|
|
133
|
+
response=response,
|
|
134
|
+
)
|
|
119
135
|
if not model_type:
|
|
120
|
-
return
|
|
136
|
+
return j_obj
|
|
121
137
|
|
|
122
|
-
return model_type.deserialize(
|
|
138
|
+
return model_type.deserialize(j_obj)
|
|
123
139
|
|
|
140
|
+
def _resp_to_json(
|
|
141
|
+
self,
|
|
142
|
+
response: httpx.Response,
|
|
143
|
+
parse_float=None,
|
|
144
|
+
):
|
|
145
|
+
try:
|
|
146
|
+
return response.json(parse_float=parse_float)
|
|
147
|
+
except UnicodeDecodeError:
|
|
148
|
+
# try to decompress manually
|
|
149
|
+
import gzip
|
|
150
|
+
import brotli
|
|
151
|
+
|
|
152
|
+
content_encoding = response.headers.get("Content-Encoding", "").lower()
|
|
153
|
+
content = response.content
|
|
154
|
+
|
|
155
|
+
if "gzip" in content_encoding:
|
|
156
|
+
content = gzip.decompress(content)
|
|
157
|
+
elif "br" in content_encoding:
|
|
158
|
+
content = brotli.decompress(content)
|
|
159
|
+
elif "deflate" in content_encoding:
|
|
160
|
+
import zlib
|
|
161
|
+
|
|
162
|
+
content = zlib.decompress(content, -zlib.MAX_WBITS)
|
|
163
|
+
else:
|
|
164
|
+
raise ValueError(
|
|
165
|
+
f"failed to detect content encoding: {content_encoding}"
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
# Now parse the decompressed content
|
|
169
|
+
return json.loads(content.decode("utf-8"), parse_float=parse_float)
|
|
124
170
|
|
|
125
171
|
async def aclose(self) -> None:
|
|
126
172
|
await self.httpx_client.aclose()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|