I am trying to implement the Poloniex account notification websocket API in Node.js https://docs.poloniex.com/#websocket-api
The command is: { "command": "subscribe", "channel": "1000", "key": "", "payload": "nonce=", "sign": "").hexdigest()>" }
The first parts are easy however I am stuck on the sign parameter. This involves 1) encrypting my secret using hmca_sha512 2) updating it with the nonce? 3) converting it to a hex digest?
So far my code reads as follows however the last line has me stuck:
ws2.on('open', function open() {
var nonce = Date.now();
ws.send(JSON.stringify({ 'command': 'subscribe',
'channel': 1000,
'key': apiKey,
'payload': `nonce=${nonce}`,
**'sign': "<hmac_sha512(secret).update("nonce=<epoch ms>").hexdigest()>"**
}));
});
I think I can achieve the hmac_sha512 by using:
const crypto = require('crypto');
const hmac = crypto.createHmac('sha512', apiSecret);
I think I can convert a value to a hex digest using:
.toString('hex');
I am not sure of how to implement the .update("nonce=") part. I can partially update this to be as below however am lost on the "update()" function.
.update(`nonce=${nonce}`)