Skip to content

Instantly share code, notes, and snippets.

@prdn
Created September 10, 2017 09:26
Show Gist options
  • Save prdn/6f0522eaf519e9356d5a780945cef488 to your computer and use it in GitHub Desktop.
Save prdn/6f0522eaf519e9356d5a780945cef488 to your computer and use it in GitHub Desktop.
// npm install ws crypto-js
const WebSocket = require('ws')
const crypto = require('crypto-js')
const apiKey = ''
const apiSecret = ''
const authNonce = Date.now() * 1000
const authPayload = 'AUTH' + authNonce
const authSig = crypto
.HmacSHA384(authPayload, apiSecret)
.toString(crypto.enc.Hex)
const wss = new WebSocket('wss://api.bitfinex.com/ws/2')
wss.onmessage = (msg) => console.log(msg.data)
wss.onopen = () => {
const payload = {
apiKey,
authSig,
authNonce,
authPayload,
event: 'auth'
}
wss.send(JSON.stringify(payload))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment