I want to use websockets to get the exchange rate from the Bitfex exchange. But in the browser I get an error
<html> <div id="btc"></div> <script> var ws = new WebSocket("wss://api2.bitfinex.com:3000/ws"); 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[7]; } }; </script> </html> Mistake
failed: Error in connection establishment: net::ERR_NAME_NOT_RESOLVED Table output using php
$req = json_decode(file_get_contents("https://api.bitfinex.com/v1/book/BTCUSD"), true); echo "<table><tr><td>Bids</td><td>Asks</td></tr>"; $bids = $req["bids"]; echo "<tr><td valign='top'>"; foreach($bids as $details){ echo "$".$details["price"]." - ".$details["amount"]; echo "<br>"; } echo "</td><td valign='top'>"; $asks = $req["asks"]; foreach($asks as $askDetails){ echo "$".$askDetails["price"]." - ".$askDetails["amount"]; echo "<br>"; } echo "</td></tr></table>"; Orderbuk
<script> var ws = new WebSocket("wss://api-pub.bitfinex.com/ws/2"); ws.onopen = function(){ ws.send(JSON.stringify({ event: 'conf', flags: 131072 })) let msg = JSON.stringify({ event: 'subscribe', channel: 'book', pair: 'tBTCUSD', prec: 'P0' }) ws.send(msg) ws.onmessage = function(msg){ var response = JSON.parse(msg.data); console.log(response); } } </script> 