Created
February 26, 2018 19:43
-
-
Save webuti/f0a31e8f914fda06ef4102fd4a957c70 to your computer and use it in GitHub Desktop.
bitfinex ws ticket
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
const WebSocket = require('ws') | |
const wss = new WebSocket('wss://api.bitfinex.com/ws/2') | |
var bitfinexcr = ['tBTCUSD', 'tETHUSD', 'tXRPUSD', 'tBCHUSD', 'tDSHUSD', 'tETCUSD', 'tLTCUSD', 'tREPUSD', 'tXMRUSD', 'tZECUSD']; | |
wss.onopen = function () { | |
bitfinexcr.forEach(function (currency) { | |
wss.send(JSON.stringify({ | |
"event": "subscribe", | |
"channel": "ticker", | |
"pair": currency | |
})); | |
}); | |
}; | |
var symbol = []; | |
var pair = []; | |
wss.onmessage = function (msg) { | |
var response = JSON.parse(msg.data); | |
var hb = response[1]; | |
if (hb != "hb") { | |
switch (response.event) { | |
case 'subscribed': | |
eval(" symbol[" + response.chanId + "] = '" + response.symbol + "'; pair[" + response.chanId + "] = '" + response.pair + "'; "); | |
break; | |
default: | |
if (response[0]) { | |
switch (pair[response[0]]) { | |
case 'BTCUSD': | |
console.log(pair[response[0]] + ' BID: ' + response[1][0] + ' ASK: ' + response[1][2]); | |
break; | |
default: | |
console.log(pair[response[0]] + ' BID: ' + response[1][0] + ' ASK: ' + response[1][2]); | |
break; | |
} | |
} | |
break; | |
} | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment