I am trying to create a real time tiker of the price of bitcoin from the BTC-E.com exchange in Ukrainian currency. The end result is to put the price on my simple html website. The exchange does not provide the price in hrivna (UAH), so i have to convert from BTC to USD to UAH.
I am using the api provided by BTC-E
https://btc-e.com/api/2/btc_usd/ticker
this is the php file i have created
<?php
header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
header('Pragma: no-cache'); // HTTP 1.0.
header('Expires: 0'); // Proxies.
$data = file_get_contents("https://btc-e.com/api/2/btc_usd/ticker");
$data = json_decode($data, true);
$spot_last = $data['ticker']['last'];
echo $spot_last;
?>
and this is the code i put in index.html
<script>
var auto_refresh = setInterval(
function()
{$('.btce_price').load('ticker.php');}, 1000);
</script>
In order to have USD to UAH conversion i would like to use the commercial rate from one of the banks.
https://api.privatbank.ua/p24api/pubinfo?exchange&coursid=5
whis returns the following
<exchangerates>
<row>
<exchangerate ccy="RUR" base_ccy="UAH" buy="0.25000" sale="0.28000"/>
</row>
<row>
<exchangerate ccy="EUR" base_ccy="UAH" buy="13.30000" sale="14.30000"/>
</row>
<row>
<exchangerate ccy="USD" base_ccy="UAH" buy="9.60000" sale="10.10000"/>
</row>
</exchangerates>
so i have the other php file to output the buy rate that i need
$xml = simplexml_load_file("https://api.privatbank.ua/p24api/pubinfo?exchange&coursid=5");
$m = $xml->xpath('//exchangerate[@ccy="USD"]');
$exrate = (string)$m[0]['buy'];
echo $exrate;
Now I want to knwo how to divide the output of the first file buy the second? Need help