how can i get data from GDAX Bitfinex using API and show like bottom

0

how can i get and show below link data, can someone please help me

https://runcoders.com/live-bitcoin/

i am trying by this but failed to show like up link

<?php
//define API endpoint
$url = "https://api.gdax.com/products/BTC-USD/stats";

//fetch the url and convert the JSON into an associative array
$fgc = json_decode(file_get_contents($url), true);

//assign values to variables
$open = $fgc["open"];
$high = $fgc["high"];
$low = $fgc["low"];
$close = $fgc["close"];
?>
<html>
<h1>My Website</h1>
<p>Bitcoin 24 HR stats</p>
Open: $<?php echo $open; ?><br>
High: $<?php echo $high; ?><br>
Low: $<?php echo $low; ?><br>
Close: $<?php echo $close; ?><br>
</html>

user3308270

Posted 2018-06-07T07:44:19.843

Reputation: 3

Answers

0

They are just using websocket to connect to the exchange and then outputting the lives trades to the page by appending it to an element.

Here's a simple example using bitfinex:

<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>

m1xolyd1an

Posted 2018-06-07T07:44:19.843

Reputation: 3 356