mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
python: add parse_time
This commit is contained in:
parent
b576a221fc
commit
17ce9fa90b
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -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),
|
||||
)
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user