python: update README.md

This commit is contained in:
なるみ 2022-04-13 23:25:23 +08:00
parent 9b8eb0642d
commit 20dfe4fbeb

View File

@ -12,18 +12,25 @@ pip install .
### Stream ### Stream
```python ```python
from loguru import logger
from bbgo import Stream 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) class LogBook(UpdateHandler):
stream.on_book_event(book_event_callback)
stream.on_ticker_event(ticker_event_callback) 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() stream.start()
``` ```