trd-utils 0.0.25__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.25 → trd_utils-0.0.27}/PKG-INFO +1 -1
- {trd_utils-0.0.25 → trd_utils-0.0.27}/pyproject.toml +1 -1
- trd_utils-0.0.27/trd_utils/__init__.py +3 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/exchange_base.py +55 -9
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/types_helper/base_model.py +15 -4
- trd_utils-0.0.25/trd_utils/__init__.py +0 -3
- {trd_utils-0.0.25 → trd_utils-0.0.27}/LICENSE +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/README.md +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/cipher/__init__.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/common_utils/float_utils.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/common_utils/wallet_utils.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/date_utils/__init__.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/date_utils/datetime_helpers.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/README.md +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/__init__.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/base_types.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/blofin/__init__.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/blofin/blofin_client.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/blofin/blofin_types.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/bx_ultra/__init__.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/bx_ultra/bx_types.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/bx_ultra/bx_ultra_client.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/bx_ultra/bx_utils.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/hyperliquid/README.md +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/hyperliquid/__init__.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/hyperliquid/hyperliquid_client.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/hyperliquid/hyperliquid_types.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/okx/__init__.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/okx/okx_client.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/exchanges/okx/okx_types.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/html_utils/__init__.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/html_utils/html_formats.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/tradingview/__init__.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/tradingview/tradingview_client.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/tradingview/tradingview_types.py +0 -0
- {trd_utils-0.0.25 → trd_utils-0.0.27}/trd_utils/types_helper/__init__.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()
|
|
@@ -47,6 +47,14 @@ def get_real_attr(cls, attr_name):
|
|
|
47
47
|
return None
|
|
48
48
|
|
|
49
49
|
|
|
50
|
+
def is_base_model_type(expected_type: type) -> bool:
|
|
51
|
+
return (
|
|
52
|
+
expected_type is not None
|
|
53
|
+
and expected_type != Any
|
|
54
|
+
and issubclass(expected_type, BaseModel)
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
50
58
|
def is_any_type(target_type: type) -> bool:
|
|
51
59
|
return target_type == Any or target_type is type(None)
|
|
52
60
|
|
|
@@ -92,16 +100,17 @@ def value_to_normal_obj(value, omit_none: bool = False):
|
|
|
92
100
|
result[inner_key] = normalized_value
|
|
93
101
|
|
|
94
102
|
return result
|
|
95
|
-
|
|
103
|
+
|
|
96
104
|
if isinstance(value, datetime.datetime):
|
|
97
105
|
return dt_to_ts(value)
|
|
98
106
|
|
|
99
107
|
raise TypeError(f"unsupported type provided: {type(value)}")
|
|
100
108
|
|
|
109
|
+
|
|
101
110
|
def convert_to_expected_type(
|
|
102
111
|
expected_type: type,
|
|
103
112
|
value: Any,
|
|
104
|
-
default_value
|
|
113
|
+
default_value=None,
|
|
105
114
|
):
|
|
106
115
|
try:
|
|
107
116
|
return expected_type(value)
|
|
@@ -148,7 +157,7 @@ def generic_obj_to_value(
|
|
|
148
157
|
)
|
|
149
158
|
return result
|
|
150
159
|
|
|
151
|
-
if isinstance(value, dict) and
|
|
160
|
+
if isinstance(value, dict) and is_base_model_type(expected_type=expected_type):
|
|
152
161
|
if len(expected_type_args) > 1:
|
|
153
162
|
raise ValueError(
|
|
154
163
|
"unsupported operation: at this time we cannot have"
|
|
@@ -249,7 +258,9 @@ class BaseModel:
|
|
|
249
258
|
)
|
|
250
259
|
|
|
251
260
|
# Handle nested models
|
|
252
|
-
elif isinstance(value, dict) and
|
|
261
|
+
elif isinstance(value, dict) and is_base_model_type(
|
|
262
|
+
expected_type=expected_type
|
|
263
|
+
):
|
|
253
264
|
value = expected_type(**value)
|
|
254
265
|
|
|
255
266
|
elif isinstance(value, list):
|
|
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
|