'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
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?
Solution 1:[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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Arturo |
