Bitfinex API WebSocket

时间:2019-04-25 16:42:45

标签: javascript websocket

如何在bitfinex交易所上使用websocket获取一对BTCUSD的最新价格?我用这种方法尝试,但没有带来任何好处

<html>
<div id="btc"></div>
<script>
var ws = new WebSocket("wss://api-pub.bitfinex.com/ws/2");
ws.onopen = function(){
  ws.send(JSON.stringify({"event":"subscribe", "channel":"ticker", "pair":"BTCUSD"}))
};
ws.onmessage = function(msg){
  var response = JSON.parse(msg.data);
  var hb = response[1];
  if(hb != "hb"){
    document.getElementById("btc").innerHTML = "$" + response[1][1];
  }
};

</script>
</html>

0 个答案:

没有答案