Author

Topic: Why this PHP code is not posting BTC price in USD on 29-08-2019? (Read 245 times)

member
Activity: 107
Merit: 168
Security Researcher and Writer
As all of these users said, coingecko might have rate-limited you or your IP was blocked. If you're under VPN, there's high chance that Coingecko rate-limited/banned you from the service.
hero member
Activity: 1456
Merit: 940
🇺🇦 Glory to Ukraine!
CounterEntropy, as others have already said, your code works fine. It is possible that you are blocked on the server side. Try to open the url of the API endpoint in your browser. Do you get a proper response? Try changing your IP address if you can.
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
You know, it would really make this a lot simpler if you post the CURL error code or server response you got here.

What do you get when you visit the page? Both of your codes are working fine on my end. Tongue

It returns 9753.4870488971, which matches what the API endpoint returns (with the last digit being rounded).

Yup, both of his codes are working fine. I checked it as well.

Something similar happened to me once, there was nothing wrong with code and still it wasn't working. Turned out that my server's IP address was being blocked by Cloudflare. Maybe something similar is happening to OP.

Try making a simple curl request to the api, and see what response you get.

Alternatively, try connecting with a proxy (spin up a temporary VPS for at BitVPS for just $1 and install Squid on it, and try connecting with that).
sr. member
Activity: 1064
Merit: 382
Hurrah for Karamazov!
What do you get when you visit the page? Both of your codes are working fine on my end. Tongue

It returns 9753.4870488971, which matches what the API endpoint returns (with the last digit being rounded).

Yup, both of his codes are working fine. I checked it as well.

Something similar happened to me once, there was nothing wrong with code and still it wasn't working. Turned out that my server's IP address was being blocked by Cloudflare. Maybe something similar is happening to OP.

Try making a simple curl request to the api, and see what response you get.
legendary
Activity: 2758
Merit: 6830
What do you get when you visit the page? Both of your codes are working fine on my end. Tongue

It returns 9753.4870488971, which matches what the API endpoint returns (with the last digit being rounded).
legendary
Activity: 3374
Merit: 3095
Playbet.io - Crypto Casino and Sportsbook
I think this is not the right place to talk about this I think the development and technical or project development section is the right section for this. I'll ask mods to move this thread

Anyway, about your PHP issue have you read the Coingecko API documentation? I think you need to try to ping your API status through this command below to check if your API is online

Code:
$data = $client->ping();


Also, I would like to ask if you already created an account in Coingecko is it a free one that has limited API request daily?

I think you can try the Coingecko PHP code from this link below it might help how to install/use those codes properly.

- https://github.com/codenix-sv/coingecko-api
full member
Activity: 214
Merit: 278
Neither this...
Code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.coingecko.com/api/v3/coins/bitcoin/history?date=29-08-2019&localization=false');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
$object = json_decode($response);
$usdVal = $object->market_data->current_price->usd;
echo $usdVal;

Nor this...
Code:
ini_set('max_execution_time', 300);
$url ='https://api.coingecko.com/api/v3/coins/bitcoin/history?date=29-08-2019&localization=false';
$data = file_get_contents($url);
$object = json_decode($data);
$usdVal = $object->market_data->current_price->usd;
echo $usdVal;

What am I doing wrong?


p.s. I could not find a better place to ask this question on BitcoinTalk. So, asking it here. If mods think, it does not fit here, feel free to move.
Jump to: