From 20dfe4fbebe91ea91b12f0296360d07493034765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=82=8B=E3=81=BF?= Date: Wed, 13 Apr 2022 23:25:23 +0800 Subject: [PATCH] python: update README.md --- python/README.md | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) 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() ```