bbgo_origin/python/bbgo/data/kline.py

42 lines
1019 B
Python
Raw Normal View History

2022-04-13 06:52:34 +00:00
from __future__ import annotations
2022-04-13 06:00:28 +00:00
from dataclasses import dataclass
from datetime import datetime
2022-04-13 06:52:34 +00:00
import bbgo_pb2
from ..utils import parse_float
2022-04-18 03:40:39 +00:00
from ..utils import parse_time
2022-04-13 06:00:28 +00:00
@dataclass
class KLine:
exchange: str
symbol: str
open: float
high: float
low: float
close: float
volume: float
session: str = None
start_time: datetime = None
end_time: datetime = None
quote_volume: float = None
closed: bool = None
2022-04-13 06:52:34 +00:00
@classmethod
def from_pb(cls, obj: bbgo_pb2.KLine) -> KLine:
return cls(
exchange=obj.exchange,
symbol=obj.symbol,
open=parse_float(obj.open),
high=parse_float(obj.high),
low=parse_float(obj.low),
close=parse_float(obj.close),
volume=parse_float(obj.volume),
quote_volume=parse_float(obj.quote_volume),
2022-04-18 03:40:39 +00:00
start_time=parse_time(obj.start_time),
end_time=parse_time(obj.end_time),
2022-04-13 06:52:34 +00:00
closed=obj.closed,
)