I'm using the CoinMarketCap API to get the price of multiples crypto-currencies.
My PHP function is the following :
function updateCryptoPrice($conn, $Symbol)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=$Symbol&convert=USD",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Accept: application/json",
"Accept-Encoding: deflate, gzip",
"X-CMC_PRO_API_KEY: b38d4ec2-9a5e-4509-8381-0051dd83a6f2"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
}
$price = json_decode($response, true);
$price = $price['data']["$Symbol"]['quote']['USD']['price'];
echo $price;
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
date_default_timezone_set('Europe/Paris');
$lastupdate = date('d-m-y h:i');
$sql = "
UPDATE `CryptosPrices` SET `Price` = '$price', `LastUpdate` = '$lastupdate'
WHERE Symbol='$Symbol'; ";
if ($conn->query($sql) === TRUE) {
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
It work perfectly on local, but when I upload it on my production server nothing work, I try to echo the $response but nothing happen and I have no error.
Do you think it come from Coinmarketcap ? My side ?
I've been on this problem for hours and can't figure out where is the problem (no error ..)
Thank you !