bbgo_origin/python/bbgo/data/ticker.py

32 lines
678 B
Python
Raw Normal View History

from __future__ import annotations
from dataclasses import dataclass
2022-05-13 08:30:19 +00:00
from decimal import Decimal
import bbgo_pb2
2022-05-13 08:30:19 +00:00
from ..utils import parse_number
@dataclass
class Ticker:
exchange: str
symbol: str
2022-05-13 08:30:19 +00:00
open: Decimal
high: Decimal
low: Decimal
close: Decimal
volume: Decimal
@classmethod
def from_pb(cls, obj: bbgo_pb2.KLine) -> Ticker:
return cls(
exchange=obj.exchange,
symbol=obj.symbol,
2022-05-13 08:30:19 +00:00
open=parse_number(obj.open),
high=parse_number(obj.high),
low=parse_number(obj.low),
close=parse_number(obj.close),
volume=parse_number(obj.volume),
)