0

CoinMarketCap Api 通过调用不同的链接来提供大量数据。每次您拨打电话需要 1 个信用点数,当然,如果该呼叫返回 5,000 个硬币,则需要 25 个信用点数。所以,我不能每分钟都调用不同的链接。如何拨打至少 4 个链接,例如:

  1. https://pro-api.coinmarketcap.com/v1/cryptocurrency/trending/latest
  2. https://pro-api.coinmarketcap.com/v1/cryptocurrency/trending/gainers-losers
  3. https://pro-api.coinmarketcap.com/cryptocurrency/listings/latest?limit=5000
  4. 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
4

1 回答 1

0

您可以使用 curl_multi_init 异步处理多个 curl 请求。你可以在这里阅读更多关于多卷曲的信息

于 2021-09-03T04:52:50.683 回答