简体   繁体   English

如何按市值获得 coingecko API 的 300 个首枚硬币的列表?

[英]How can I get a list of the 300 first coins of coingecko API by marketcap?

If I make a request to get the full list of coingecko coins using with如果我请求使用 with 获取coingecko硬币的完整列表

https://api.coingecko.com/api/v3/coins/list

and get the ids of each coins taking the 'id' entry.并获取每个带有'id'条目的硬币的 id。

Then I can loop on all coins id with a然后我可以循环使用所有硬币 id

https://api.coingecko.com/api/v3/simple/price?ids=<coin>&vs_currencies=usd

(in which <coin> should be replaced by the id coming from the full list) (eg https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd to get bitcoin price), and then reorder it by marketcap. (其中<coin>应替换为来自完整列表的 id)(例如https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd以获取比特币价格),以及然后按市值重新排序。

This works but the problem is that there are many requests and this is taking ages (a few hours at least).这可行,但问题是有很多请求,这需要很长时间(至少几个小时)。

It there a possibility to immediately get the id of the first 300 coins by marketcap?是否有可能立即按市值获得前 300 个硬币的 id?

There is Coingecco API request markets that returns coin price, market cap and market cap rank among other info. Coingecco API 请求markets返回硬币价格、市值和市值排名等信息。 You can sort it by market cap rank and just take 300 first elements of JSON array.您可以按市值排名对其进行排序,然后只取 JSON 数组的 300 个第一个元素。

https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc

Response looks like:响应如下:

[
  {
    "id": "bitcoin",
    "symbol": "btc",
    "name": "Bitcoin",
    "image": "https://assets.coingecko.com/coins/images/1/large/bitcoin.png?1547033579",
    "current_price": 9664.88,
    "market_cap": 178353923560,
    "market_cap_rank": 1,
    ...
    "last_updated": "2020-07-26T05:05:03.478Z"
  },
  {
    "id": "ethereum",
    "symbol": "eth",
    "name": "Ethereum",
    "image": "https://assets.coingecko.com/coins/images/279/large/ethereum.png?1595348880",
    "current_price": 302.53,
    "market_cap": 33895800150,
    "market_cap_rank": 2,
...
    },

UPD: To get exactly 300 results use the following request: UPD:要准确获得 300 个结果,请使用以下请求:

https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=100&page=3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM