<?php 

include('../classes/database.class.php');

$listOfCurrencies = "USD_SGD";
$date = date('Y-m-d');
$time = date('H:i');


$ch = curl_init("https://api-fxtrade.oanda.com/v3/accounts/001-001-414778-001/pricing?instruments=" . $listOfCurrencies);
$header = array();
$header[] = 'Content-type: application/json';
$header[] = 'Authorization: Bearer c143ece96a9cb2ce9dc6ecdbaf844523-77cf55b79018d06cf3396c90855d06be';
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$resultsj = curl_exec($ch);
$results = json_decode($resultsj);
$db = new database();



	if (!isset($results->errorMessage)) {
	# code...
	$getrate = $results->prices[0]->bids[0]->price;
	$getaskrate = $results->prices[0]->asks[0]->price;
	$getcloseoutask = $results->prices[0]->closeoutAsk;

	}else{

	$firstsymbol = substr($listOfCurrencies, 0, 3);
	$secondsymbol = substr($listOfCurrencies, 4, 6);
	$fullSymbol = $secondsymbol."_".$firstsymbol;

	$newch = curl_init("https://api-fxtrade.oanda.com/v3/accounts/001-001-414778-001/pricing?instruments=" . $fullSymbol);
	curl_setopt($newch, CURLOPT_HTTPHEADER, $header);
	curl_setopt($newch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($newch, CURLOPT_SSL_VERIFYPEER, false);
	$newresultsj = curl_exec($newch);
	$newresults = json_decode($newresultsj);
	$rate = $newresults->prices[0]->bids[0]->price;
	$newrate = 1 / $rate;

	$ask_rate = $newresults->prices[0]->asks[0]->price;
	$getaskrate = 1 / $ask_rate;
	$getaskrate = number_format((float)$getaskrate, 5, '.', '');

	$getrate = number_format((float)$newrate, 5, '.', '');

	}


	echo $getcloseoutask;

	/*$q = ;
	$query = $db->db->prepare($q);
	$query->execute();*/


?>