Bitcoin Forum
June 25, 2024, 09:28:23 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Why this PHP code is not posting BTC price in USD on 29-08-2019?  (Read 231 times)
CounterEntropy (OP)
Full Member
***
Offline Offline

Activity: 214
Merit: 278


View Profile
August 29, 2022, 05:23:09 PM
 #1

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.
BitMaxz
Legendary
*
Offline Offline

Activity: 3290
Merit: 3030


BTC price road to $80k


View Profile WWW
August 29, 2022, 11:56:53 PM
 #2

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

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
TryNinja
Legendary
*
Offline Offline

Activity: 2870
Merit: 7119


Crypto Swap Exchange


View Profile WWW
August 30, 2022, 01:11:04 AM
 #3

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).

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
edgycorner
Sr. Member
****
Offline Offline

Activity: 1064
Merit: 382

Hurrah for Karamazov!


View Profile
August 30, 2022, 04:47:21 AM
 #4

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.
NotATether
Legendary
*
Offline Offline

Activity: 1638
Merit: 6912


bitcoincleanup.com / bitmixlist.org


View Profile WWW
August 30, 2022, 05:50:14 AM
 #5

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).

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
decodx
Hero Member
*****
Offline Offline

Activity: 1456
Merit: 935

🇺🇦 Glory to Ukraine!


View Profile
August 30, 2022, 08:53:13 PM
 #6

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.
serhack
Member
**
Offline Offline

Activity: 107
Merit: 168

Security Researcher and Writer


View Profile WWW
September 10, 2022, 09:09:45 AM
 #7

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.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!