15

If I make a request to get the full list of coingecko coins using with

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

and get the ids of each coins taking the 'id' entry.

Then I can loop on all coins id with a

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) (e.g. https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd to get bitcoin price), and then reorder it by marketcap.

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?

Braiam
  • 1
  • 11
  • 47
  • 78
saturn
  • 161
  • 1
  • 1
  • 6

2 Answers2

19

There is Coingecco API request markets that returns coin price, market cap and market cap rank among other info. You can sort it by market cap rank and just take 300 first elements of JSON array.

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:

https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=100&page=3
Yuri Ginsburg
  • 2,302
  • 2
  • 13
  • 16
  • 2
    Thanks you very much, that exactly the kind requests I was searching! But here the problem is that this request gives just the 100 first coins. Do you know how to exactly the same result, but for more than 100 coins? – saturn Jul 26 '20 at 15:08
  • I have updated the answer providing therequest that gives exactly 300 results. – Yuri Ginsburg Jul 26 '20 at 20:32
  • 1
    This doesn't look correct to me, &per_page=100&page=3 this just give you the 3rd page with 100 total records. Unfortunately, the API just support max 250 or page, means the only way to get 300 is to do 2 calls like &per_page=150&page=1 plus &per_page=150&page=2. In my case, I would like Coincheck API to have the option in the endpoint .../coins/list to return the results ordered by the marketCap. – Marco Martins Oct 21 '20 at 13:18
  • Have you ever figured this out? Looking for pretty much the same thing right now – Martin Conde Aug 23 '21 at 12:12
1

To fetch the coins you are going to use this api url:

https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=250&page=1&sparkline=true&price_change_percentage=24h

Some important notes:

  • You can change the currency on the request where it says USD
  • Each request can accept a max of 250 coins and you are starting on page 1. So, if you need the first 300 coins you would loop that request 2 time, and that would give you 250+250 = 500 coins, you can then stop at the 300 by looking at the index of the array in your view.
  • Sparkline contains the prices of 7 days. The values are divided by hour, and the last one in the array is the most recent.
Arturo
  • 3,254
  • 2
  • 22
  • 61