2022-04-14 07:36:29 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-04-13 06:00:28 +00:00
|
|
|
from dataclasses import dataclass
|
|
|
|
from datetime import datetime
|
|
|
|
|
2022-04-14 07:36:29 +00:00
|
|
|
import bbgo_pb2
|
|
|
|
|
2022-04-13 06:00:28 +00:00
|
|
|
from ..enums import OrderType
|
|
|
|
from ..enums import SideType
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Order:
|
2022-04-14 07:36:29 +00:00
|
|
|
exchange: str
|
|
|
|
symbol: str
|
2022-04-13 06:00:28 +00:00
|
|
|
order_id: str
|
|
|
|
side: SideType
|
|
|
|
order_type: OrderType
|
|
|
|
price: float
|
|
|
|
stop_price: float
|
|
|
|
status: str
|
2022-04-14 07:36:29 +00:00
|
|
|
quantity: float
|
|
|
|
executed_quantity: float
|
2022-04-13 06:00:28 +00:00
|
|
|
client_order_id: str
|
2022-04-14 07:36:29 +00:00
|
|
|
group_id: int
|
|
|
|
created_at: datetime
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def from_pb(cls, obj: bbgo_pb2.Order) -> Order:
|
|
|
|
return cls(
|
|
|
|
exchange=obj.exchange,
|
|
|
|
symbol=obj.symbol,
|
|
|
|
order_id=obj.id,
|
|
|
|
side=SideType.from_pb(obj.side),
|
|
|
|
order_type=OrderType.from_pb(obj.order_type),
|
|
|
|
price=float(obj.price),
|
|
|
|
stop_price=float(obj.stop_price),
|
|
|
|
status=obj.status,
|
|
|
|
quantity=float(obj.quantity),
|
|
|
|
executed_quantity=float(obj.executed_quantity),
|
|
|
|
client_order_id=obj.client_order_id,
|
|
|
|
group_id=obj.group_id,
|
|
|
|
created_at=datetime.fromtimestamp(obj.created_at / 1000),
|
|
|
|
)
|