trd-utils 0.0.24__tar.gz → 0.0.26__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.24 → trd_utils-0.0.26}/PKG-INFO +1 -1
- {trd_utils-0.0.24 → trd_utils-0.0.26}/pyproject.toml +1 -1
- trd_utils-0.0.26/trd_utils/__init__.py +3 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/types_helper/base_model.py +37 -5
- trd_utils-0.0.24/trd_utils/__init__.py +0 -3
- {trd_utils-0.0.24 → trd_utils-0.0.26}/LICENSE +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/README.md +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/cipher/__init__.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/common_utils/float_utils.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/common_utils/wallet_utils.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/date_utils/__init__.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/date_utils/datetime_helpers.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/README.md +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/__init__.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/base_types.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/blofin/__init__.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/blofin/blofin_client.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/blofin/blofin_types.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/bx_ultra/__init__.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/bx_ultra/bx_types.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/bx_ultra/bx_ultra_client.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/bx_ultra/bx_utils.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/exchange_base.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/hyperliquid/README.md +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/hyperliquid/__init__.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/hyperliquid/hyperliquid_client.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/hyperliquid/hyperliquid_types.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/okx/__init__.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/okx/okx_client.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/exchanges/okx/okx_types.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/html_utils/__init__.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/html_utils/html_formats.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/tradingview/__init__.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/tradingview/tradingview_client.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/tradingview/tradingview_types.py +0 -0
- {trd_utils-0.0.24 → trd_utils-0.0.26}/trd_utils/types_helper/__init__.py +0 -0
|
@@ -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,13 +100,29 @@ 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
|
|
|
101
109
|
|
|
110
|
+
def convert_to_expected_type(
|
|
111
|
+
expected_type: type,
|
|
112
|
+
value: Any,
|
|
113
|
+
default_value=None,
|
|
114
|
+
):
|
|
115
|
+
try:
|
|
116
|
+
return expected_type(value)
|
|
117
|
+
except Exception:
|
|
118
|
+
if value == "":
|
|
119
|
+
try:
|
|
120
|
+
return expected_type()
|
|
121
|
+
except Exception:
|
|
122
|
+
return default_value
|
|
123
|
+
return default_value
|
|
124
|
+
|
|
125
|
+
|
|
102
126
|
def generic_obj_to_value(
|
|
103
127
|
expected_type: type,
|
|
104
128
|
expected_type_args: tuple[type],
|
|
@@ -133,7 +157,7 @@ def generic_obj_to_value(
|
|
|
133
157
|
)
|
|
134
158
|
return result
|
|
135
159
|
|
|
136
|
-
if isinstance(value, dict) and
|
|
160
|
+
if isinstance(value, dict) and is_base_model_type(expected_type=expected_type):
|
|
137
161
|
if len(expected_type_args) > 1:
|
|
138
162
|
raise ValueError(
|
|
139
163
|
"unsupported operation: at this time we cannot have"
|
|
@@ -144,7 +168,10 @@ def generic_obj_to_value(
|
|
|
144
168
|
if not expected_type_args:
|
|
145
169
|
if value is None or isinstance(value, expected_type):
|
|
146
170
|
return value
|
|
147
|
-
return
|
|
171
|
+
return convert_to_expected_type(
|
|
172
|
+
expected_type=expected_type,
|
|
173
|
+
value=value,
|
|
174
|
+
)
|
|
148
175
|
|
|
149
176
|
raise TypeError(f"unsupported type: {type(value)}")
|
|
150
177
|
|
|
@@ -231,7 +258,9 @@ class BaseModel:
|
|
|
231
258
|
)
|
|
232
259
|
|
|
233
260
|
# Handle nested models
|
|
234
|
-
elif isinstance(value, dict) and
|
|
261
|
+
elif isinstance(value, dict) and is_base_model_type(
|
|
262
|
+
expected_type=expected_type
|
|
263
|
+
):
|
|
235
264
|
value = expected_type(**value)
|
|
236
265
|
|
|
237
266
|
elif isinstance(value, list):
|
|
@@ -266,7 +295,10 @@ class BaseModel:
|
|
|
266
295
|
# Type checking
|
|
267
296
|
elif not (is_any_type(expected_type) or isinstance(value, expected_type)):
|
|
268
297
|
try:
|
|
269
|
-
value =
|
|
298
|
+
value = convert_to_expected_type(
|
|
299
|
+
expected_type=expected_type,
|
|
300
|
+
value=value,
|
|
301
|
+
)
|
|
270
302
|
except Exception:
|
|
271
303
|
raise TypeError(
|
|
272
304
|
f"Field {corrected_key} must be of type {expected_type},"
|
|
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
|