bbgo_origin/python/bbgo/utils/convert.py

21 lines
369 B
Python
Raw Normal View History

2022-04-18 03:45:03 +00:00
from datetime import datetime
2022-05-13 08:30:19 +00:00
from decimal import Decimal
2022-04-18 03:45:03 +00:00
from typing import Union
2022-05-13 08:30:19 +00:00
def parse_number(s: Union[str, float]) -> Decimal:
2022-04-18 03:45:03 +00:00
if s is None:
return 0
if s == "":
return 0
2022-05-13 08:30:19 +00:00
return Decimal(s)
2022-04-18 03:45:03 +00:00
def parse_time(t: Union[str, int]) -> datetime:
if isinstance(t, str):
t = int(t)
2022-04-22 06:18:17 +00:00
return datetime.fromtimestamp(t / 1000)