diff --git a/python/README.md b/python/README.md index 69eb92945..e0b3a9f63 100644 --- a/python/README.md +++ b/python/README.md @@ -12,18 +12,25 @@ pip install . ### Stream ```python +from loguru import logger + from bbgo import Stream -from bbgo import bbgo_pb2 +from bbgo.data import Event +from bbgo.handlers import UpdateHandler -subscriptions = [ - bbgo_pb2.Subscription(exchange='max', channel=bbgo_pb2.Channel.BOOK, symbol='btcusdt', depth=2), - bbgo_pb2.Subscription(exchange='max', channel=bbgo_pb2.Channel.BOOK, symbol='ethusdt', depth=2), - ... -] -stream = Stream(host, port, subscriptions) -stream.on_book_event(book_event_callback) -stream.on_ticker_event(ticker_event_callback) -... +class LogBook(UpdateHandler): + + def handle(self, event: Event) -> None: + logger.info(event) + + +host = '127.0.0.1' +port = 50051 + +stream = Stream(host, port) +stream.subscribe('max', 'book', 'BTCUSDT', 'full') +stream.subscribe('max', 'book', 'ETHUSDT', 'full') +stream.add_event_handler(LogBook()) stream.start() ```