CoinMarketCap Api 通过调用不同的链接来提供大量数据。每次您拨打电话需要 1 个信用点数,当然,如果该呼叫返回 5,000 个硬币,则需要 25 个信用点数。所以,我不能每分钟都调用不同的链接。如何拨打至少 4 个链接,例如:
- https://pro-api.coinmarketcap.com/v1/cryptocurrency/trending/latest
- https://pro-api.coinmarketcap.com/v1/cryptocurrency/trending/gainers-losers
- https://pro-api.coinmarketcap.com/cryptocurrency/listings/latest?limit=5000
- https://pro-api.coinmarketcap.com/v2/cryptocurrency/info
这是 CoinMarketCap 提供的代码,它可以工作(经过测试):
$url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest';
$parameters = [
'start' => '1',
'limit' => '5000',
'convert' => 'USD'
];
$headers = [
'Accepts: application/json',
'X-CMC_PRO_API_KEY: *********-****-****-****-***********'
];
$qs = http_build_query($parameters); // query string encode the parameters
$request = "{$url}?{$qs}"; // create the request URL
$curl = curl_init(); // Get cURL resource
//Set cURL options
curl_setopt_array($curl, array(
CURLOPT_URL => $request, // set the request URL
CURLOPT_HTTPHEADER => $headers, // set the headers
CURLOPT_RETURNTRANSFER => 1 // ask for raw response instead of bool
));
$response = curl_exec($curl); // Send the request, save the response
print_r(json_decode($response)); // print json decoded response
curl_close($curl); // Close request