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-05-13 08:30:19 +00:00
|
|
|
from decimal import Decimal
|
2022-04-13 06:00:28 +00:00
|
|
|
|
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
|
2022-05-13 08:30:19 +00:00
|
|
|
from ..utils import parse_number
|
2022-04-18 03:40:39 +00:00
|
|
|
from ..utils import parse_time
|
2022-04-13 06:00:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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
|
2022-05-13 08:30:19 +00:00
|
|
|
price: Decimal
|
|
|
|
stop_price: Decimal
|
2022-04-13 06:00:28 +00:00
|
|
|
status: str
|
2022-05-13 08:30:19 +00:00
|
|
|
quantity: Decimal
|
|
|
|
executed_quantity: Decimal
|
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,
|
2022-04-15 06:57:33 +00:00
|
|
|
side=SideType(obj.side),
|
|
|
|
order_type=OrderType(obj.order_type),
|
2022-05-13 08:30:19 +00:00
|
|
|
price=parse_number(obj.price),
|
|
|
|
stop_price=parse_number(obj.stop_price),
|
2022-04-14 07:36:29 +00:00
|
|
|
status=obj.status,
|
2022-05-13 08:30:19 +00:00
|
|
|
quantity=parse_number(obj.quantity),
|
|
|
|
executed_quantity=parse_number(obj.executed_quantity),
|
2022-04-14 07:36:29 +00:00
|
|
|
client_order_id=obj.client_order_id,
|
|
|
|
group_id=obj.group_id,
|
2022-04-18 03:40:39 +00:00
|
|
|
created_at=parse_time(obj.created_at),
|
2022-04-14 07:36:29 +00:00
|
|
|
)
|