Comment on page
#1: Get Data by ID or Address
First thing first, here’s few key rules that help you understand the basics
Do you know that by knowing how to use ‘id’ and ‘contract address’, you’re already able to use about half of the 30+ endpoints offered by CoinGecko API?
This is one of the most widely used endpoint to get the latest price of Bitcoin:
e.g. try to click on this link below:
You will see ids=bitcoin and vs_currencies=usd on the link above, it means we’re trying to get the price of bitcoin in USD.
How do we get the ids of specific coins? There are 3 options:
- 1.Use /coins/list API endpoint, it will return the full list of Coins available on CoinGecko. You may then search for coin in the list using “name” and “symbol”, then obtain the “id” of specific coins.
- 1.Reminder: “name” and “symbol” might change in the future, they are not unique. ”id” is the main unique identifier for different coins for you to use with CoinGecko API.
Other than using Coin ID, you may also query price & market data of a coin using contract address:
In the query above, there are 3 values that we need to input:
usd← vs_currencies (more on this in the next section)
While trying to query an endpoint using contract address, you must also specify the asset platform, which is equivalent to ‘blockchain network’. You may use the following endpoint to find the ids of all asset platforms supported by CoinGecko:
How do we get the contract address of specific coins? There are 2 options:
Not all coins will have contract address on CoinGecko site.
If an address is not shown on CoinGecko page, you will not be able to query the coin by contract address via API
If a address is not shown on CoinGecko page, you will not be able to query the coin by contract address via API
- 1.You might get it from project wesbsite, whitepaper, documentation, or block explorer site like Etherscan. e.g. for Uniswap:
In the 2 examples above, both queries for Coin ID and Contract Address contain
vs_currencies=usd. Most CoinGecko API endpoints require you to specify the currency.
CoinGecko API data supports all major fiat currencies and some famous crypto currencies like the following:
You can view the full list of supported currencies here:
The /coins/market endpoint will allow you to query Coins data in bulk. e.g.
Let’s deep dive a little bit on the parameters included above:
- vs_currency: usd
- order: market_cap_desc ← the data will be ranked from the largest to smallest Market Cap.
- per_page: 100 ← here it specifies that the page should contain 100 coins (max is 250 coins per page)
- page: 1 ←here it specifies the page number. if you input ‘2’ here and per_page=100 , then you will get the 101st-200th coin on CoinGecko, ranked by Market Cap, which is similar as the result of https://www.coingecko.com/?page=2