Yahoo finance rates convert (for educational purposes only)
Posted on October 22, 2019, 10:30 am, by admin, under
php.
<?php
class Rates {
function Convert($amount,$from,$to){
$url="http://adsynth-ofx-quotewidget-prod.herokuapp.com/api/1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"method":"spotRateHistory","data":{"base":"'.$from.'","term":"'.$to.'","period":"week"}}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_REFERER, "https://widget-yahoo.ofx.com/");
$html = curl_exec ($ch);
curl_close ($ch);
$veri=json_decode($html,true);
return $veri["data"]["CurrentInterbankRate"]*$amount;
}
}
$kur = new Rates();
echo $kur->Convert(1, 'USD', 'GBP'); |