mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
23 lines
612 B
Python
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)
|