bbgo_origin/python/tests/test_data.py

81 lines
2.3 KiB
Python
Raw Normal View History

2022-04-13 06:52:34 +00:00
import bbgo_pb2
from bbgo.data import Balance
from bbgo.data import ErrorMessage
from bbgo.data import KLine
2022-04-18 03:40:39 +00:00
from bbgo.utils import parse_time
def test_balance_from_pb():
exchange = 'max'
currency = 'BTCUSDT'
available = '3.1415926'
locked = '2.7182818'
borrowed = 'borrowed'
balance_pb = bbgo_pb2.Balance(
exchange=exchange,
currency=currency,
available=available,
locked=locked,
borrowed=borrowed,
)
balance = Balance.from_pb(balance_pb)
assert balance.exchange == exchange
assert balance.currency == currency
assert balance.available == float(available)
assert balance.locked == float(locked)
assert balance.borrowed == borrowed
2022-04-13 06:52:34 +00:00
def test_kline_from_pb():
exchange = "binance"
symbol = "BTCUSDT"
open = "39919.31"
high = "39919.32"
low = "39919.31"
close = "39919.31"
volume = "0.27697"
quote_volume = "11056.4530226"
start_time = 1649833260000
end_time = 1649833319999
closed = True
kline_pb = bbgo_pb2.KLine(exchange=exchange,
symbol=symbol,
open=open,
high=high,
low=low,
close=close,
volume=volume,
quote_volume=quote_volume,
start_time=start_time,
end_time=end_time,
closed=closed)
kline = KLine.from_pb(kline_pb)
assert kline.exchange == exchange
assert kline.symbol == symbol
assert kline.open == float(open)
assert kline.high == float(high)
assert kline.low == float(low)
assert kline.close == float(close)
assert kline.volume == float(volume)
assert kline.quote_volume == float(quote_volume)
2022-04-18 03:40:39 +00:00
assert kline.start_time == parse_time(start_time)
assert kline.end_time == parse_time(end_time)
2022-04-13 06:52:34 +00:00
assert closed == closed
def test_order_from_pb():
error_code = 123
error_message = "error message 123"
error_pb = bbgo_pb2.Error(error_code=error_code, error_message=error_message)
error = ErrorMessage.from_pb(error_pb)
assert error.code == error_code
assert error.message == error_message