Hi there,
I’m having a tough time trying to subscribe to wss://ws-direct.exchange.coinbase.com
I cannot authenticate using the API key and secret that I have created.
What I’ve tried:
Proved that the API key and secret I’ve got are valid and enabled - they work to call a REST endpoint that requires authentication like GET https://api.coinbase.com/v2/user .
Using the following code:
const timestamp = (Date.now() / 1000).toFixed(0) + ''
const p_apiKey = process.env.COINBASE_API_KEY;
const p_secret = process.env.COINBASE_API_SECRET;
const what = timestamp + 'GET' + '/users/self/verify'
const key = Buffer.from(p_secret, 'base64')
const hmac = crypto.createHmac('sha256', key)
const signature = hmac.update(what).digest('base64')
const subscribeData = {
"type": "subscribe",
"product_ids": [
"BTC-GBP"
],
"channels": [
"level2",
"heartbeat",
{
"name": "ticker",
"product_ids": [
"ETH-GBP",
"BTC-GBP"
]
}
],
'key': p_apiKey,
'signature': signature,
'timestamp': timestamp
}
connection.send(JSON.stringify(subscribeData))
I get the following message back:
{
type: 'error',
message: 'Authentication Failed',
reason: 'authentication required'
}
I noticed that on the basic https REST API, I had to use the API secret raw, rather than base64 encoded, and digest(‘hex’) instead of digest(‘base64’), but neither seems to work on the WSS.
I got this from the coinbase npm package, and looking into what it does.
I tried the coinbase-pro npm package, and that seems to require a passphrase.
When I created my API key, it never gave me a passphrase. A bit of googling suggests that only coinbase pro created API keys have a passphrase, so I went to pro.coinbase.com, and it said it is deprecated.
Does anybody have any ideas on how to subscribe to this WSS feed?