trd-utils 0.0.23__py3-none-any.whl → 0.0.25__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.

Potentially problematic release.


This version of trd-utils might be problematic. Click here for more details.

trd_utils/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
 
2
- __version__ = "0.0.23"
2
+ __version__ = "0.0.25"
3
3
 
@@ -44,7 +44,7 @@ class UserPositionInfo(BaseModel):
44
44
  mark_px: Decimal = None
45
45
  mgn_mode: str = None
46
46
  mgn_ratio: Decimal = None
47
- notional_usd: int = None
47
+ notional_usd: Decimal = None
48
48
  pnl: Decimal = None
49
49
  pos: Decimal = None
50
50
  pos_ccy: str = None
@@ -98,6 +98,21 @@ def value_to_normal_obj(value, omit_none: bool = False):
98
98
 
99
99
  raise TypeError(f"unsupported type provided: {type(value)}")
100
100
 
101
+ def convert_to_expected_type(
102
+ expected_type: type,
103
+ value: Any,
104
+ default_value = None,
105
+ ):
106
+ try:
107
+ return expected_type(value)
108
+ except Exception:
109
+ if value == "":
110
+ try:
111
+ return expected_type()
112
+ except Exception:
113
+ return default_value
114
+ return default_value
115
+
101
116
 
102
117
  def generic_obj_to_value(
103
118
  expected_type: type,
@@ -144,7 +159,10 @@ def generic_obj_to_value(
144
159
  if not expected_type_args:
145
160
  if value is None or isinstance(value, expected_type):
146
161
  return value
147
- return expected_type(value)
162
+ return convert_to_expected_type(
163
+ expected_type=expected_type,
164
+ value=value,
165
+ )
148
166
 
149
167
  raise TypeError(f"unsupported type: {type(value)}")
150
168
 
@@ -266,7 +284,10 @@ class BaseModel:
266
284
  # Type checking
267
285
  elif not (is_any_type(expected_type) or isinstance(value, expected_type)):
268
286
  try:
269
- value = expected_type(value)
287
+ value = convert_to_expected_type(
288
+ expected_type=expected_type,
289
+ value=value,
290
+ )
270
291
  except Exception:
271
292
  raise TypeError(
272
293
  f"Field {corrected_key} must be of type {expected_type},"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: trd_utils
3
- Version: 0.0.23
3
+ Version: 0.0.25
4
4
  Summary: Common Basic Utils for Python3. By ALiwoto.
5
5
  Keywords: utils,trd_utils,basic-utils,common-utils
6
6
  Author: ALiwoto
@@ -1,4 +1,4 @@
1
- trd_utils/__init__.py,sha256=ycZRLTPOff6iyw6emCSdTkhoNYR94Dl7xx09yStvLVE,25
1
+ trd_utils/__init__.py,sha256=ya5l9DV6rbzbgF3LG_OERJrXy20GL9syFL-MON5solU,25
2
2
  trd_utils/cipher/__init__.py,sha256=V05KNuzQwCic-ihMVHlC8sENaJGc3I8MCb4pg4849X8,1765
3
3
  trd_utils/common_utils/float_utils.py,sha256=W-jv7nzjl88xwGB6gsEXmDDhF6DseOrrVT2qx7OvyCo,266
4
4
  trd_utils/common_utils/wallet_utils.py,sha256=OX9q2fymP0VfIWTRIRBP8W33cfyjLXimxMgPOsZe-3g,727
@@ -21,15 +21,15 @@ trd_utils/exchanges/hyperliquid/hyperliquid_client.py,sha256=dE-WIj1_H_5qHnO2Uu4
21
21
  trd_utils/exchanges/hyperliquid/hyperliquid_types.py,sha256=MiGG5fRU7wHqOMtCzQXD1fwwbeUK1HEcQwW5rl-9D4c,2678
22
22
  trd_utils/exchanges/okx/__init__.py,sha256=OjVpvcwB9mrCTofLt14JRHV2-fMAzGz9-YkJAMwl6dM,67
23
23
  trd_utils/exchanges/okx/okx_client.py,sha256=M6P1lDJ2UDqT7WMvXgiK4BbUwa73OHvh-8Dbo51oOqo,7118
24
- trd_utils/exchanges/okx/okx_types.py,sha256=u9Y2vxcja1DvlclAxB1g3LDznei8bZLKNGEzgCSLGFw,5009
24
+ trd_utils/exchanges/okx/okx_types.py,sha256=IkFOfgivcvvIw950jyGHAVfFFGbGqfZcYGfZLWfNLvc,5013
25
25
  trd_utils/html_utils/__init__.py,sha256=1WWs8C7JszRjTkmzIRLHpxWECHur_DrulTPGIeX88oM,426
26
26
  trd_utils/html_utils/html_formats.py,sha256=unKsvOiiDmYTTaM0DYZEUNLEUzWQKKrqASJXvY54kvU,2299
27
27
  trd_utils/tradingview/__init__.py,sha256=H0QYb-O5qvy7qC3yswtlcSWLmeBnaS6oJ3JtjvmaV_Y,154
28
28
  trd_utils/tradingview/tradingview_client.py,sha256=g_eWYaCRQAL8Kvd-r6AnAdbH7Jha6C_GAyCuxh-RQUU,3917
29
29
  trd_utils/tradingview/tradingview_types.py,sha256=z21MXPVdWHAduEl3gSeMIRhxtBN9yK-jPYHfZSMIbSA,6144
30
30
  trd_utils/types_helper/__init__.py,sha256=lLbUiW1jUV1gjzTMFLthwkvF0hwauH-F_J2JZq--1U0,67
31
- trd_utils/types_helper/base_model.py,sha256=EEVEfIpXc5_HhQMAfWXan1i7WFmj7MZvCuwnw3zBgtI,11029
32
- trd_utils-0.0.23.dist-info/LICENSE,sha256=J1EP2xt87RjjmsTV1jTjHDQMLIM9FjdwEftTpw8hyv4,1067
33
- trd_utils-0.0.23.dist-info/METADATA,sha256=TMmJW3ynSCFdDvx3-J2Vd4p3y65hL8YNkYR_KY0EB1s,1095
34
- trd_utils-0.0.23.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
35
- trd_utils-0.0.23.dist-info/RECORD,,
31
+ trd_utils/types_helper/base_model.py,sha256=tu5PYwxD5aYtQgJ2oVL7qPT9lIXUNxRow8YGVxM5zVg,11571
32
+ trd_utils-0.0.25.dist-info/LICENSE,sha256=J1EP2xt87RjjmsTV1jTjHDQMLIM9FjdwEftTpw8hyv4,1067
33
+ trd_utils-0.0.25.dist-info/METADATA,sha256=z08ADWgMrzRSX8Onkbx9oRAAk6Dv0zWg2f-Yr6_S2Rs,1095
34
+ trd_utils-0.0.25.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
35
+ trd_utils-0.0.25.dist-info/RECORD,,