Skip to content

Commit bb66088

Browse files
committed
Updated README to reflect OrderBook changes
1 parent 5d38d21 commit bb66088

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,30 @@ python -m pytest
346346
```
347347

348348
### Real-time OrderBook
349-
The ```OrderBook``` subscribes to a websocket and keeps a real-time record of
350-
the orderbook for the product_id input. Please provide your feedback for future
349+
The ```OrderBook``` is a convenient data structure to keep a real-time record of
350+
the orderbook for the product_id input. It processes incoming messages from an
351+
already existing WebsocketClient. Please provide your feedback for future
351352
improvements.
352353

353354
```python
354-
import cbpro, time
355-
order_book = cbpro.OrderBook(product_id='BTC-USD')
356-
order_book.start()
355+
import cbpro, time, Queue
356+
class myWebsocketClient(cbpro.WebsocketClient):
357+
def on_open(self):
358+
self.products = ['BTC-USD', 'ETH-USD']
359+
self.websocket_queue = Queue.Queue()
360+
def on_message(self, msg):
361+
self.websocket_queue.put(msg)
362+
363+
order_book_btc = cbpro.OrderBook(product_id='BTC-USD')
364+
order_book_eth = cbpro.OrderBook(product_id='ETH-USD')
365+
wsClient = myWebsocketClient()
366+
wsClient.start()
357367
time.sleep(10)
358-
order_book.close()
368+
while True:
369+
msg = wsClient.websocket_queue.get(timeout=15)
370+
order_book.process_message(msg)
371+
print(order_book_btc.get_ask())
372+
print(order_book_eth.get_bid())
359373
```
360374

361375
### Testing

0 commit comments

Comments
 (0)