Last active
April 7, 2020 14:02
-
-
Save prdn/fab10103ad76b0f8f79deb3540239fe2 to your computer and use it in GitHub Desktop.
bfx-perf-auth-order-21.js
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
// INSTALL | |
// requirements: node.js interpreter | |
// run: npm install ws | |
const WebSocket = require('ws') | |
const crypto = require('crypto') | |
const fs = require('fs') | |
const w1_apiKey = 'API_KEY' | |
const w1_apiSecret = 'API_SECRET' | |
const w1 = new WebSocket('wss://api.bitfinex.com/ws/2') | |
const authNonce = (new Date()).getTime() * 1000 | |
const payload = 'AUTH' + authNonce | |
const signature = crypto.createHmac('sha384', w1_apiSecret).update(payload).digest('hex') | |
w1.on('message', function(data) { | |
console.log(Date.now(), data) | |
}) | |
w1.on('open', function() { | |
w1.send(JSON.stringify({ event: 'conf', flags: 32768 })) | |
w1.send(JSON.stringify({ | |
event: 'auth', | |
apiKey: w1_apiKey, | |
authSig: signature, | |
authPayload: payload, | |
authNonce: +authNonce | |
})) | |
setTimeout(() => { | |
console.log(Date.now(), 'send') | |
for (let i = 0; i < 10; i++) { | |
w1.send(JSON.stringify([0, 'on', null, { gid: 1, cid: 12345 + i, type: "EXCHANGE LIMIT", symbol: "tBTCUSD", amount: '0.1', price: '100', hidden: 0 }])) | |
} | |
}, 2000) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment