trd-utils 0.0.18__tar.gz → 0.0.19__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.18 → trd_utils-0.0.19}/PKG-INFO +1 -1
- {trd_utils-0.0.18 → trd_utils-0.0.19}/pyproject.toml +1 -1
- trd_utils-0.0.19/trd_utils/__init__.py +3 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/date_utils/datetime_helpers.py +9 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/types_helper/base_model.py +9 -2
- trd_utils-0.0.18/trd_utils/__init__.py +0 -3
- {trd_utils-0.0.18 → trd_utils-0.0.19}/LICENSE +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/README.md +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/cipher/__init__.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/common_utils/float_utils.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/date_utils/__init__.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/exchanges/README.md +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/exchanges/__init__.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/exchanges/base_types.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/exchanges/blofin/__init__.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/exchanges/blofin/blofin_client.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/exchanges/blofin/blofin_types.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/exchanges/bx_ultra/__init__.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/exchanges/bx_ultra/bx_types.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/exchanges/bx_ultra/bx_ultra_client.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/exchanges/bx_ultra/bx_utils.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/exchanges/exchange_base.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/exchanges/hyperliquid/README.md +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/exchanges/hyperliquid/__init__.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/exchanges/hyperliquid/hyperliquid_client.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/exchanges/hyperliquid/hyperliquid_types.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/html_utils/__init__.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/html_utils/html_formats.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/tradingview/__init__.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/tradingview/tradingview_client.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/tradingview/tradingview_types.py +0 -0
- {trd_utils-0.0.18 → trd_utils-0.0.19}/trd_utils/types_helper/__init__.py +0 -0
|
@@ -14,3 +14,12 @@ def dt_from_ts(timestamp: float) -> datetime:
|
|
|
14
14
|
# Timezone in ms - convert to seconds
|
|
15
15
|
timestamp /= 1000
|
|
16
16
|
return datetime.fromtimestamp(timestamp, tz=timezone.utc)
|
|
17
|
+
|
|
18
|
+
def dt_to_ts(dt: datetime, default: int = 0) -> int:
|
|
19
|
+
"""
|
|
20
|
+
Return dt in ms as a timestamp in UTC.
|
|
21
|
+
If dt is None, return the given default.
|
|
22
|
+
"""
|
|
23
|
+
if dt:
|
|
24
|
+
return int(dt.timestamp() * 1000)
|
|
25
|
+
return default
|
|
@@ -10,6 +10,7 @@ from typing import (
|
|
|
10
10
|
|
|
11
11
|
import dateutil.parser
|
|
12
12
|
|
|
13
|
+
from trd_utils.date_utils.datetime_helpers import dt_from_ts, dt_to_ts
|
|
13
14
|
from trd_utils.html_utils.html_formats import camel_to_snake
|
|
14
15
|
|
|
15
16
|
# Whether to use ultra-list instead of normal python list or not.
|
|
@@ -91,6 +92,9 @@ def value_to_normal_obj(value, omit_none: bool = False):
|
|
|
91
92
|
result[inner_key] = normalized_value
|
|
92
93
|
|
|
93
94
|
return result
|
|
95
|
+
|
|
96
|
+
if isinstance(value, datetime.datetime):
|
|
97
|
+
return dt_to_ts(value)
|
|
94
98
|
|
|
95
99
|
raise TypeError(f"unsupported type provided: {type(value)}")
|
|
96
100
|
|
|
@@ -244,9 +248,12 @@ class BaseModel:
|
|
|
244
248
|
|
|
245
249
|
if ULTRA_LIST_ENABLED and isinstance(value, list):
|
|
246
250
|
value = convert_to_ultra_list(value)
|
|
247
|
-
elif expected_type is datetime.datetime
|
|
251
|
+
elif expected_type is datetime.datetime:
|
|
248
252
|
try:
|
|
249
|
-
|
|
253
|
+
if isinstance(value, str):
|
|
254
|
+
value = dateutil.parser.parse(value)
|
|
255
|
+
elif isinstance(value, int):
|
|
256
|
+
value = dt_from_ts(value)
|
|
250
257
|
except Exception as ex:
|
|
251
258
|
raise ValueError(
|
|
252
259
|
f"Failed to parse the string as datetime: {value}"
|
|
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
|