Timestamp Retrieve And Persist - NFSandbox/sh_trade_backend GitHub Wiki
Retrieve
All timestamp used in this system should be generated or converted to align with UTC timezone. In python, we created a utility function to retrieve current timestamp in UTC:
def get_current_timestamp_ms() -> int:
return int(datetime.now(UTC).timestamp() * 1000)
For more info about timestamp and timezone in Python, please read this blog article.
Here notice we are using Milliseconds Timestamp which have 13 digits in total.
Persistence
Currently, all timestmap info is represent by using int
type in Python, and which will also be used to interact with SQLAlchemy. Base on the custom mapping config in the ORMBaseClass
:
class SQLBaseModel(AsyncAttrs, DeclarativeBase):
deleted: Mapped[bool] = mapped_column(default=False)
type_annotation_map = {int: BIGINT}
All int
value in Python will finally be mapped into BIGINT
fields in our database.