Created
September 10, 2017 09:26
-
-
Save prdn/6f0522eaf519e9356d5a780945cef488 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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