본문 바로가기
블록체인

api call 테스트

by "뭉치" 2021. 8. 27.
728x90
전체 복사 후

notepad - 메모장 열고

붙여놓고

저장 할 때 

​

apicall.html 로 저장한 뒤

더블 클릭

<html>
<body>
<div id="view">

<div>
</body>
<script>
var ws = new WebSocket("wss://api2.bitfinex.com:3000/ws");
var index = 0;

ws.onopen = function(){
  ws.send(JSON.stringify({"event":"subscribe", "channel":"ticker", "pair":"BTCUSD"}))
};

ws.onmessage = function(msg){

  var response = JSON.parse(msg.data);
  var info = 'bitfinex.com api<br> "event":"subscribe", "channel":"ticker", "pair":"BTCUSD"<br><br>';
  var hb = response[1];
  if( hb != "hb"){
    console.log(response);
    if ( index == 0 ) { 
      document.write(info); 
      index++; 
    }
    document.write("ASK: " + response[3]+"<br>"+ "LAST: " + response[7] + "<br> BID: " + response[1] + "<br><br>");
  }
};
</script>
</html>
728x90

댓글