Skip to content

Commit f900479

Browse files
authored
Merge pull request danpaquin#4 from adamgilman/master
Support multiple products via websockets stream
2 parents 0eae1ba + f57d75f commit f900479

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

GDAX/WebsocketClient.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ def __init__(self, ws_url="wss://ws-feed.gdax.com", product_id="BTC-USD"):
2020
def setup(self):
2121
self.open()
2222
self.ws = create_connection(self.url)
23-
subParams = json.dumps({"type": "subscribe", "product_id": self.product_id})
23+
if type(self.product_id) is list:
24+
#product_ids - plural for multiple products
25+
subParams = json.dumps({"type": "subscribe", "product_ids": self.product_id})
26+
else:
27+
subParams = json.dumps({"type": "subscribe", "product_id": self.product_id})
2428
self.ws.send(subParams)
2529
self.listen()
2630

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ authClient.withdraw(withdrawParams)
193193

194194
### WebsocketClient
195195
If you would like to receive real-time market updates, you must subscribe to the [websocket feed](https://docs.gdax.com/#websocket-feed).
196+
197+
#### Subscribe to a single product
196198
```python
197199
import GDAX
198200
# Paramters are optional
@@ -201,6 +203,15 @@ wsClient = GDAX.WebsocketClient(ws_url="wss://ws-feed.gdax.com", product_id="BTC
201203
wsClient.close()
202204
```
203205

206+
#### Subscribe to multiple products
207+
```python
208+
import GDAX
209+
# Paramters are optional
210+
wsClient = GDAX.WebsocketClient(ws_url="wss://ws-feed.gdax.com", product_id=["BTC-USD", "ETH-USD"])
211+
# Do other stuff...
212+
wsClient.close()
213+
```
214+
204215
### WebsocketClient Methods
205216
The ```WebsocketClient``` subscribes in a separate thread upon initialization. There are three methods which you could overwrite (before initialization) so it can react to the data streaming in. The current client is a template used for illustration purposes only.
206217

@@ -228,4 +239,4 @@ The following projects are suggested to improve the functionality of this projec
228239
- [**danielktaylor/PyLimitBook**](https://github.com/danielktaylor/PyLimitBook)
229240
*Python implementation of fast limit-order book.*
230241
- [**PierreRochard/coinbase-exchange-order-book**](https://github.com/PierreRochard/coinbase-exchange-order-book)
231-
*Real-time Coinbase Exchange order book + basic market maker bot (Python3)*
242+
*Real-time Coinbase Exchange order book + basic market maker bot (Python3)*

0 commit comments

Comments
 (0)