bbgo_origin/python/bbgo/data/kline.py

43 lines
1.0 KiB
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-05-13 08:30:19 +00:00
from decimal import Decimal
2022-04-13 06:00:28 +00:00
2022-04-13 06:52:34 +00:00
import bbgo_pb2
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 KLine:
exchange: str
symbol: str
2022-05-13 08:30:19 +00:00
open: Decimal
high: Decimal
low: Decimal
close: Decimal
volume: Decimal
2022-04-13 06:00:28 +00:00
session: str = None
start_time: datetime = None
end_time: datetime = None
2022-05-13 08:30:19 +00:00
quote_volume: Decimal = None
2022-04-13 06:00:28 +00:00
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,
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),
quote_volume=parse_number(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,
)