2022-04-14 07:36:29 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from datetime import datetime
|
2022-05-13 08:30:19 +00:00
|
|
|
from decimal import Decimal
|
2022-04-14 07:36:29 +00:00
|
|
|
|
|
|
|
import bbgo_pb2
|
|
|
|
|
|
|
|
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-14 07:36:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Trade:
|
|
|
|
session: str
|
|
|
|
exchange: str
|
|
|
|
symbol: str
|
2022-04-20 07:00:44 +00:00
|
|
|
trade_id: str
|
2022-05-13 08:30:19 +00:00
|
|
|
price: Decimal
|
|
|
|
quantity: Decimal
|
2022-04-14 07:36:29 +00:00
|
|
|
created_at: datetime
|
|
|
|
side: SideType
|
|
|
|
fee_currency: str
|
2022-05-13 08:30:19 +00:00
|
|
|
fee: Decimal
|
2022-04-14 07:36:29 +00:00
|
|
|
maker: bool
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def from_pb(cls, obj: bbgo_pb2.Trade) -> Trade:
|
|
|
|
return cls(
|
|
|
|
session=obj.session,
|
|
|
|
exchange=obj.exchange,
|
|
|
|
symbol=obj.symbol,
|
2022-04-22 08:58:00 +00:00
|
|
|
trade_id=obj.id,
|
2022-05-13 08:30:19 +00:00
|
|
|
price=parse_number(obj.price),
|
|
|
|
quantity=parse_number(obj.quantity),
|
2022-04-18 03:40:39 +00:00
|
|
|
created_at=parse_time(obj.created_at),
|
2022-04-14 07:36:29 +00:00
|
|
|
side=SideType(obj.side),
|
|
|
|
fee_currency=obj.fee_currency,
|
2022-05-13 08:30:19 +00:00
|
|
|
fee=parse_number(obj.fee),
|
2022-04-14 07:36:29 +00:00
|
|
|
maker=obj.maker,
|
|
|
|
)
|