freqtrade_origin/freqtrade/util/datetime_helpers.py
2023-05-18 07:00:36 +02:00

23 lines
612 B
Python

from datetime import datetime, timezone
def dt_now() -> datetime:
"""Return the current datetime in UTC."""
return datetime.now(timezone.utc)
def dt_now_ts() -> int:
"""Return the current timestamp in ms as a timestamp in UTC."""
return int(dt_now().timestamp() * 1000)
def dt_from_ts(timestamp: float) -> datetime:
"""
Return a datetime from a timestamp.
:param timestamp: timestamp in seconds or milliseconds
"""
if timestamp > 1e10:
# Timezone in ms - convert to seconds
timestamp /= 1000
return datetime.fromtimestamp(timestamp, tz=timezone.utc)