bbgo_origin/python/bbgo/data/trade.py

42 lines
949 B
Python
Raw Normal View History

from __future__ import annotations
from dataclasses import dataclass
from datetime import datetime
import bbgo_pb2
from ..enums import SideType
from ..utils import parse_float
2022-04-18 03:40:39 +00:00
from ..utils import parse_time
@dataclass
class Trade:
session: str
exchange: str
symbol: str
trade_id: str
price: float
quantity: float
created_at: datetime
side: SideType
fee_currency: str
fee: float
maker: bool
@classmethod
def from_pb(cls, obj: bbgo_pb2.Trade) -> Trade:
return cls(
session=obj.session,
exchange=obj.exchange,
symbol=obj.symbol,
id=obj.id,
price=parse_float(obj.price),
quantity=parse_float(obj.quantity),
2022-04-18 03:40:39 +00:00
created_at=parse_time(obj.created_at),
side=SideType(obj.side),
fee_currency=obj.fee_currency,
fee=parse_float(obj.fee),
maker=obj.maker,
)