'fetch and decode coinmarketcap JSON data with PHP using file_get_contents
I want to display the current USDT Volume of upbit.
I have used coinmarketcap api for this. https://pro-api.coinmarketcap.com/v1/exchange/info
The problem i am facing is that it returns Undefined index: spot_volume_usd in.
What i am doing is
$url = "https://pro-api.coinmarketcap.com/v1/exchange/info?CMC_PRO_API_KEY={KEY}&slug=upbit";
$stats = json_decode(file_get_contents($url), true);
$usdtvalue = $stats["spot_volume_usd"];
echo $usdtvalue."<br>";
The api response is
{"status":{"timestamp":"2022-01-25T23:23:22.154Z","error_code":0,"error_message":null,"elapsed":9,"credit_count":1,"notice":null},"data":{"upbit":{"id":351,"name":"Upbit","slug":"upbit","description":null,"notice":"","logo":"https://s2.coinmarketcap.com/static/img/exchanges/64x64/351.png","countries":[],"fiats":["KRW"],"urls":{"twitter":["https://twitter.com/upbitglobal"],"chat":["https://pf.kakao.com/_DWxgVxl"],"website":["https://upbit.com/"],"fee":["https://upbit.com/service_center/guide"],"blog":[]},"tags":null,"type":"","date_launched":"2017-10-24T00:00:00.000Z","is_hidden":0,"is_redistributable":null,"maker_fee":0,"taker_fee":0,"spot_volume_usd":2684246187.212572,"spot_volume_last_updated":"2022-01-25T23:20:15.673Z","weekly_visits":3124629}}}
What is the best way to achieve this ? Thanks in advance!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
