File tree Expand file tree Collapse file tree 1 file changed +20
-6
lines changed Expand file tree Collapse file tree 1 file changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -346,16 +346,30 @@ python -m pytest
346
346
```
347
347
348
348
### 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
351
352
improvements.
352
353
353
354
``` 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()
357
367
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())
359
373
```
360
374
361
375
### Testing
You can’t perform that action at this time.
0 commit comments