diff --git a/lib/clients/websocket.js b/lib/clients/websocket.js index 3f1be79f..57f4bc46 100644 --- a/lib/clients/websocket.js +++ b/lib/clients/websocket.js @@ -14,7 +14,7 @@ class WebsocketClient extends EventEmitter { productIDs, websocketURI = 'wss://ws-feed.gdax.com', auth = null, - { heartbeat = false } = {} + { heartbeat = false, channels = null } = {} ) { super(); this.productIDs = Utils.determineProductIDs(productIDs); @@ -24,6 +24,7 @@ class WebsocketClient extends EventEmitter { 'Invalid or incomplete authentication credentials. You should either provide all of the secret, key and passphrase fields, or leave auth null' ); } + this.channels = channels; this.auth = auth || {}; this.heartbeat = heartbeat; this.connect(); @@ -61,9 +62,17 @@ class WebsocketClient extends EventEmitter { product_ids: this.productIDs, }; + if (this.channels) { + subscribeMessage.channels = this.channels; + } + // Add Signature if (this.auth.secret) { - let sig = signRequest(this.auth, 'GET', '/users/self'); + let sig = signRequest( + this.auth, + 'GET', + this.channels ? '/users/self/verify' : '/users/self' + ); Object.assign(subscribeMessage, sig); } @@ -71,7 +80,7 @@ class WebsocketClient extends EventEmitter { if (this.heartbeat) { // send heartbeat - var heartbeatMessage = { + const heartbeatMessage = { type: 'heartbeat', on: true, }; diff --git a/package.json b/package.json index 99be47f1..0111b2ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gdax", - "version": "0.4.3", + "version": "0.4.4", "author": "Coinbase", "bugs": "https://github.com/coinbase/gdax-node/issues", "contributors": [ diff --git a/tests/websocket.spec.js b/tests/websocket.spec.js index 6704235e..b4c7613b 100644 --- a/tests/websocket.spec.js +++ b/tests/websocket.spec.js @@ -130,6 +130,34 @@ suite('WebsocketClient', () => { }); }); }); + + test('passes channels through', done => { + const server = testserver(++port, () => { + new Gdax.WebsocketClient( + 'ETH-USD', + 'ws://localhost:' + port, + { + key: 'suchkey', + secret: 'suchsecret', + passphrase: 'muchpassphrase', + }, + { channels: ['user', 'ticker'] } + ); + }); + server.on('connection', socket => { + socket.on('message', data => { + const msg = JSON.parse(data); + assert.equal(msg.type, 'subscribe'); + assert.equal(msg.key, 'suchkey'); + assert.equal(msg.passphrase, 'muchpassphrase'); + assert.deepEqual(msg.channels, ['user', 'ticker']); + assert(msg.timestamp); + assert(msg.signature); + server.close(); + done(); + }); + }); + }); }); test('passes heartbeat details through', done => {