From 17ce9fa90be2ea369006cd59229d90989a8bbd02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=82=8B=E3=81=BF?= Date: Mon, 18 Apr 2022 11:40:39 +0800 Subject: [PATCH] python: add parse_time --- python/bbgo/data/kline.py | 5 +++-- python/bbgo/data/order.py | 3 ++- python/bbgo/data/trade.py | 3 ++- python/tests/test_data.py | 7 +++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/python/bbgo/data/kline.py b/python/bbgo/data/kline.py index 3d08d114b..3b3f89e5b 100644 --- a/python/bbgo/data/kline.py +++ b/python/bbgo/data/kline.py @@ -6,6 +6,7 @@ from datetime import datetime import bbgo_pb2 from ..utils import parse_float +from ..utils import parse_time @dataclass @@ -34,7 +35,7 @@ class KLine: close=parse_float(obj.close), volume=parse_float(obj.volume), quote_volume=parse_float(obj.quote_volume), - start_time=datetime.fromtimestamp(obj.start_time / 1000), - end_time=datetime.fromtimestamp(obj.end_time / 1000), + start_time=parse_time(obj.start_time), + end_time=parse_time(obj.end_time), closed=obj.closed, ) diff --git a/python/bbgo/data/order.py b/python/bbgo/data/order.py index 21a129263..cc5802491 100644 --- a/python/bbgo/data/order.py +++ b/python/bbgo/data/order.py @@ -8,6 +8,7 @@ import bbgo_pb2 from ..enums import OrderType from ..enums import SideType from ..utils import parse_float +from ..utils import parse_time @dataclass @@ -41,5 +42,5 @@ class Order: executed_quantity=parse_float(obj.executed_quantity), client_order_id=obj.client_order_id, group_id=obj.group_id, - created_at=datetime.fromtimestamp(obj.created_at / 1000), + created_at=parse_time(obj.created_at), ) diff --git a/python/bbgo/data/trade.py b/python/bbgo/data/trade.py index ea29b3865..a29139a83 100644 --- a/python/bbgo/data/trade.py +++ b/python/bbgo/data/trade.py @@ -6,6 +6,7 @@ from datetime import datetime import bbgo_pb2 from ..enums import SideType +from ..utils import parse_time @dataclass @@ -31,7 +32,7 @@ class Trade: id=obj.id, price=float(obj.price), quantity=float(obj.quantity), - created_at=datetime.fromtimestamp(obj.created_at / 1000), + created_at=parse_time(obj.created_at), side=SideType(obj.side), fee_currency=obj.fee_currency, fee=float(obj.fee), diff --git a/python/tests/test_data.py b/python/tests/test_data.py index c0949f440..70703c88f 100644 --- a/python/tests/test_data.py +++ b/python/tests/test_data.py @@ -1,9 +1,8 @@ -from datetime import datetime - import bbgo_pb2 from bbgo.data import Balance from bbgo.data import ErrorMessage from bbgo.data import KLine +from bbgo.utils import parse_time def test_balance_from_pb(): @@ -65,8 +64,8 @@ def test_kline_from_pb(): assert kline.close == float(close) assert kline.volume == float(volume) assert kline.quote_volume == float(quote_volume) - assert kline.start_time == datetime.fromtimestamp(start_time / 1000) - assert kline.end_time == datetime.fromtimestamp(end_time / 1000) + assert kline.start_time == parse_time(start_time) + assert kline.end_time == parse_time(end_time) assert closed == closed