GDAX Heartbeat Channel

516 Views Asked by At

I'm looking at the documentation on Coinbase's Github for the GDAX API and trying to subscribe to the heartbeat channel, but keep being returned with the below error when I utilize this code:

var websocket = new Gdax.WebsocketClient(
    ['BTC-USD'],
    'wss://ws-feed.gdax.com',
    {
        key: API_KEY,
        secret: API_SECRET,
        passphrase: API_PASSPHRASE,
    },
    { heartbeat: true }
)
  webSocket.on('message', data => {
    console.log(data);
  });

Error:

{ 
    type: 'error',
    message: 'Failed to subscribe',
    reason: 'You need to specify at least one product ID for channel heartbeat'
}
1

There are 1 best solutions below

0
On

Be sure to include "product_ids" : ["BTC-GBP"] as a field in the Json request.

So something like this should work (from their API docs)

{
    "type": "subscriptions",
    "channels": [        
        {
            "name": "heartbeat",
            "product_ids": [
                "ETH-USD",
                "ETH-EUR"
            ],
        }
    ]
}

See here https://docs.gdax.com/#subscribe