mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
python: update README.md
This commit is contained in:
parent
9b8eb0642d
commit
20dfe4fbeb
|
@ -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()
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue
Block a user