Skip to content

Commit 646e99b

Browse files
emesterhazydanpaquin
authored andcommitted
Fix OrderBook class and require channels argument for WebsocketClient (danpaquin#381)
* Fix broken OrderBook by automatically connecting to 'full' channel Resolves an issue where the OrderBook class does not receive data since the underlying WebsocketClient it uses does not connect to a channel on Coinbase's WS feed. The OrderBook class now automatically specifies the 'full' channel on init in the super() call to the WebsocketClient __init__ * Require WS channels to be specified for WebsocketClient Coinbase's API rejects connections that don't specify which channels to connect to. This commit changes the `channels` arg for the WebsocketClient class into a required keyword argument with no default value. See: https://www.python.org/dev/peps/pep-3102/ Closes danpaquin#380 Closes danpaquin#371
1 parent 0a9dbd8 commit 646e99b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

cbpro/order_book.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
class OrderBook(WebsocketClient):
1616
def __init__(self, product_id='BTC-USD', log_to=None):
17-
super(OrderBook, self).__init__(products=product_id)
17+
super(OrderBook, self).__init__(
18+
products=product_id, channels=['full'])
1819
self._asks = SortedDict()
1920
self._bids = SortedDict()
2021
self._client = PublicClient()

cbpro/websocket_client.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,21 @@
1818

1919

2020
class WebsocketClient(object):
21-
def __init__(self, url="wss://ws-feed.pro.coinbase.com", products=None, message_type="subscribe", mongo_collection=None,
22-
should_print=True, auth=False, api_key="", api_secret="", api_passphrase="", channels=None):
21+
def __init__(
22+
self,
23+
url="wss://ws-feed.pro.coinbase.com",
24+
products=None,
25+
message_type="subscribe",
26+
mongo_collection=None,
27+
should_print=True,
28+
auth=False,
29+
api_key="",
30+
api_secret="",
31+
api_passphrase="",
32+
# Make channels a required keyword-only argument; see pep3102
33+
*,
34+
# Channel options: ['ticker', 'user', 'matches', 'level2', 'full']
35+
channels):
2336
self.url = url
2437
self.products = products
2538
self.channels = channels

0 commit comments

Comments
 (0)