Skip to content

Commit

Permalink
python: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
narumiruna committed Apr 13, 2022
1 parent 9b8eb06 commit 20dfe4f
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@ pip install .
### Stream

```python
from loguru import logger

from bbgo import Stream
from bbgo import bbgo_pb2

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)
...
from bbgo.data import Event
from bbgo.handlers import UpdateHandler


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()
```

0 comments on commit 20dfe4f

Please sign in to comment.