Search API Connector Documentation

Print

Import CoinGecko Data to Google Sheets

In this guide, we’ll walk through how to pull cryptocurrency market data from the CoinGecko API directly into Google Sheets, using the API Connector add-on for Sheets. The cool thing about CoinGecko is that their API is free and open, so we won’t need any API key. They also provide some unique API endpoints like most-searched coins. The bad thing is that they severely rate limit requests through Google’s servers… you can see more on that in the “CoinGecko Limits” section.

If you want to skip the details, you can jump right to the end to grab your own copy of the CoinGecko crypto tracking template. You can also check out our YouTube tutorial video here.

BEFORE YOU BEGIN

Click here to install the API Connector add-on from the Google Marketplace.

PART 1: CREATE YOUR COINGECKO API REQUEST URL

We’ll first follow the CoinGecko API documentation to a big list of crypto coins and their current prices.

  • API root: https://api.coingecko.com
  • Endpoint: /api/v3/coins/markets
  • Query String: ?vs_currency=usd

Putting it together, we get the full API Request URL:

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

PART 2: PULL COINGECKO API DATA INTO SHEETS

Now let’s paste that URL into API Connector and import some crypto data into Google Sheets.

  1. Open up Google Sheets and click Add-ons > API Connector > Open.
  2. In the Create tab, enter the API URL we just created.
    coingecko-img1
  3. Leave the Headers section empty. We can leave authentication set to None, too.
  4. Create a new tab and click ‘Set current’ to use that tab as your data destination.
  5. Name your request and click Run. A moment later you’ll see the latest crypto data appear in your Google Sheet:
    coingecko-img2

PART 3: MORE EXAMPLE API URLS

Experiment with endpoints and query strings as described in the documentation to see other types of currency and crypto data from the API. For example, you can try the following URLs, one at a time (substitute in other coin IDs or currencies, if you like).

  • current price of bitcoin in USD
    https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd
  • specific cryptocurrencies with price, market cap, volume, and other stats
    https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin,ethereum,ripple,eos
  • historical price snapshot of Bitcoin at a specified date
    https://api.coingecko.com/api/v3/coins/bitcoin/history?date=30-12-2018
  • list of all supported coins with ids, names, and symbols
    https://api.coingecko.com/api/v3/coins/list
  • list all exchanges and related info (year established, country, trade volume, etc)
    https://api.coingecko.com/api/v3/exchanges
  • get exchange rates for BTC in every currency
    https://api.coingecko.com/api/v3/exchange_rates
    coingecko-img7
    By default the /exchange-rates request URL will return all exchange rates in a single row. To split the data into a table, you can add in a JMESPath (paid feature) query of rates.* as shown in the screenshot above.
  • most-searched coins on CoinGecko in past 24 hours
    https://api.coingecko.com/api/v3/search/trending

PART 4: HANDLE PAGINATION

  1. For several endpoints, CoinGecko limits the number of records returned in each response. By default, only 100 records will be returned unless you use the ‘page’ and ‘per_page’ parameters as shown in their documentation.
    coingecko-img5

    To get 250 records, you’d use the ‘per_page’ parameter and to return more than 250 you’d then make a second request using the ‘page’ parameter. For example:
    page 1: https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&per_page=250&page=1
    page 2: https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&per_page=250&page=2

  2. With API Connector you can either run these URLs manually or loop through them automatically with page parameter pagination handling (paid feature), like this:
    • API URL: enter your request URL as usual, making sure to include per_page=250
    • Pagination type: page parameter
    • Page parameter: page
    • Number of pages: enter the number of pages you’d like to fetch
      coingecko-img6

PART 5: COINGECKO LIMITS


If you use CoinGecko’s API for a while, you’ll probably come across an annoying problem, error messages like these:

  • API server responded with an error (429), error code: 1015
  • API server responded with an error (403): error code: 1020

The 403 error just started appearing late July 2021 and we are still learning about it. A 429 error is a rate limit error. CoinGecko limits requests to 10 calls per second per IP address, as shown in their terms & conditions:
coingecko-img8

Unfortunately, when you run your requests through API Connector / Google Sheets, you’re more likely to hit these rate limits because all requests running through Google Sheets share the same pool of IP addresses from Google’s servers.

There’s not much we can do about this except wait a minute and try again (and hope that CoinGecko whitelists Google in the future). In addition, make sure you’re combining requests into a single call wherever possible.

If you continue to have issues, you can also try pulling from a crypto API that limits by your own API key rather than the shared pool of IP addresses, e.g. CoinMarketCap or CryptoCompare.

APPENDIX: COINGECKO TEMPLATE

In this template, everything is configured for you to simply type in whatever coins you’re interested in and get a dashboard like below:
coingecko-img4

You can jump right to a copy of the template here. Happy data grabbing!

P.S. For dozens of other step-by-step guides for connecting crypto (and other) APIs to Google Sheets, click here: Knowledge Base

Previous Import Coinbase Data to Google Sheets
Next Import Coinmap Data to Google Sheets

73 thoughts on “Import CoinGecko Data to Google Sheets”

  1. Hey so i did this but it seems like it doesn’t keep up with the price fluctuations and it just stays at the original price when i set up the API, do you know the reason why this is happening?

    Reply
    • Good question. For markets, by default CoinGecko limits the amount of records they return at once. To get more you need to add &per_page=250&page=1, &per_page=250&page=2, &per_page=250&page=3, and so on to the end of your URL. I’ve just updated the article to reflect this.

      Reply
    • Hey there, this is due to the way they’ve structured their response data. If you check it in an API tool that returns the raw JSON (e.g. Swagger), you’ll notice that the response from CoinGecko uses named objects where normally you would see arrays. This prevents API Connector from recognizing where to split the data into columns vs. rows when converting the JSON response into Sheets format.
      In any case, to answer your question, you can use JMESPath, which is a very useful query language that allows you to filter and restructure the response data. The query rates.* removes the object names so that the response can be parsed correctly. I added a screenshot of this to the article.
      Note that JMESPath filtering is a paid feature, if you’re trying to do this for free, one other option is to create a second sheet containing a Sheets function like =transpose(Exchange_rates!1:2) to convert the response from one long row to one long column. I don’t think it’s a great solution but it’s still a bit better than the default response.

      Reply
  2. Hi Ana

    I came up with 3 solutions for this problem.

    Solution 1 & 2 require you to enter the formula in the first Row of 4 cells. Then drag the formula down in this case for 61 Rows since there are 61 rates returned by the API (a horizontal row of 4×61=244 cells)

    Solution 3 returns the whole table,
    after you enter the formula in the top left cell where you want the table

    Solution 1:

    =INDEX($7:$7,(ROW()-11)*4+COLUMN())

    Solution 2:

    =OFFSET(A$7,0,(ROW()-11)*4)

    Solution 3:

    Note this assumes the API data is returned on Row A7:7 – just change that to suit your Row.

    =arrayformula( query( query( iferror( if( {1,1,0}, floor( mod(row(A:A)-{1,1},{9^9, 4}), {4,1} ), transpose( split( regexreplace( query( transpose( query( transpose(A7:7 & char(9)), “”, 9^9 ) ), “”, 9^9 ), “\s+$”, “” ), char(9) & ” “, ) ) ) ), “select max(Col3) where Col3 ” group by Col1 pivot Col2″, 0 ), “offset 1”, 0 ) )

    Solution 3 is care of the experts at Docs Editors Help.

    Reply
  3. In the message above showing Solution 3 I was using the following
    URL Path = https://api.coingecko.com/api/v3/exchange_rates

    To use the Solution 3 above you need two Google Sheets
    1 – Results Sheet (This is where the table will display)
    2 – Data Sheet (This is where the API writes its ouput)

    Also where you see the function – transpose(A7:7 – this shows my data was being read from row7 – BUT –

    You should point to the sheet holding your Data with – transpose(‘Data’!A2:2 & char(9)

    Results Sheet
    =============
    Col A Col B Col C Col D
    Row(1) rates » btc » name rates » btc » unit rates » btc » value rates » btc » type
    Row(2)

    Data Sheet
    ==========
    This is where the API Connctor will put the data.
    1 – URL Path = https://api.coingecko.com/api/v3/exchange_rates
    2 – Output Option = Overwrite
    This means the data will always be written on to Row(2) starting with Cell A2

    Reply
  4. Is it possible to use the template but expand it to go beyond just 30 inputs? (I have around 100 coins I want to track). Can anyone help with what changes I would need to make?

    Thanks

    Reply
    • Should be possible, just do the following:
      1) in the Inputs tab, add in as many rows as you want
      2) in the cells Inputs!D5 and Summary!B8, change the formulas to include the new rows you added

      Reply
      • 429 errors mean you’re hitting their rate limits. The rate limit for the CoinGecko API is 10 calls each second per IP address. Unfortunately it’s easy to run into these limits, since all Sheets calls are routed through Google’s IP address pool, meaning other people are using the same resources. It should work if you wait a minute and try again.

      • Good question, I checked and I think it’s because this request sheet is set up to look for the ID rather than the symbol. In this case, the ID is “republic-protocol” while the symbol is “ren”. In many cases the ID and symbol are the same, so that’s why this problem isn’t always evident. I’ll try to make that more clear.

  5. This may be the most useful article I’ve ever found online! I was looking at the CoinGecko page on importing to Google Sheets and was getting nowhere. This is super-clear and the example spreadsheet has taken all of the work out of it. Thanks.

    Reply
  6. Hi,

    Thank you for the template, very helpful!
    I’m looking for some workaround to fit my need. I don’t understand why the “Summary” lines order is not based on the “Data” one. Each time I refresh, the order change in “Data” in relation to the market cap rank.

    How can I set up that for “Summary”?

    Thank you for your insights.

    Reply
    • The order of the Summary items comes from the Inputs tab. You can see the formula in the Summary!B8 cell.
      As you note, the order for the Data tab is set by CoinGecko, and by default is based on descending order of market cap size.
      I’m not totally sure what you’re looking to do, but if you want your data sorted by market cap, then you can just use the Data sheet, or make your own summary table that isn’t based on the Inputs tab.

      Reply
      • Thanks. I managed to do it with the Vlookup trick

        Any idea how to keep tracking my portfolio performance monthly/annually?

      • If you have a list of all your coins and their values, you could copy/paste that at the start of each month into a new column, to keep a record. My other (free) add-on Archive Data (link) automates that, you can check if it helps.

  7. Hey,
    somehow it does not work for me. I always get an “ERROR” in the cell.
    I really don`t know why? Maybe you have an idea?

    Cheers
    Lars

    Reply
    • Can you please say a little more about your request setup? Are you running your request from the sidebar or via the IMPORTAPI custom function? Where are you seeing “ERROR”, is there any more info returned when you hover over the cell?

      Reply
  8. Hi Ana, thanks for all your work with this great plugin, I was previously using json coingecko method and whilst it worked sometimes, as my portfolio grew, the scripts became less reliable.

    REFRESH BUTTON
    One thing I’m still trying to solve, is the ability to run your API via a REFRESH button on my portfolio sheet and referencing my API coingecko data from another sheet, this was a setup I made with the JSON script and worked ok.

    I have seen you mention IMPORTAPI but I’m unsure how to trigger this from the script function on the button, I suspect this might need some custom script adding as code.gs where the json was previously parked? Any help would be appreciated.

    Here’s a link to the sample sheet with the setup:
    https://docs.google.com/spreadsheets/d/1bJ5x7bqBVN4ngPcYWQTNqVqttatt5hA6XUtKp9ux-dM/edit?usp=sharing

    Would you also know how to use the sparklne data for each coin in the sheet using coingecko’s import, i have the sparkline data imported but google sheets removed support for [SPARKLINE=]

    Reply
    • Hey Fagin, thanks for the message. If you want to use IMPORTAPI, you would just set up your request in the API Connector sidebar. Then, if your request is named, say, Get Coins, you’d enter =IMPORTAPI(“Get Coins”) into any cell to run that request directly in your sheet. You can also run this request on demand by checking a box, this article has some examples of that (check the section called “Fast Cell-Based Refresh”).
      I’m not really sure what you mean about adding a custom script. I checked your sheet – it looks great – but I wasn’t sure what part you wanted me to look at (and without Edit access I can’t see your API Connector requests). So feel free to message back if you’d like to clarify anything further.

      Reply
  9. This Article is awesome!!! i’m now trying a way to adapt your template so it pulls historical prices at a certain day. Do you know if that’s possible?

    Reply
    • Thank you for the comment! You can use the ‘history’ endpoint to get historical prices. You would need to run a different request for each coin you’re looking to pull, though, like this. Please check and see if it works for you.
      https://api.coingecko.com/api/v3/coins/bitcoin/history?date=30-12-2018

      Reply
  10. Hey!
    Great application. I got a question though. Is it possible that some APIs (like in my case for the StormX coin) are not working?

    https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=stormx

    Is the command i used but the connector says “no records found”.

    Any Ideas?

    Reply
    • Hey Jonas, the problem here is that ‘stormx’ is the coin name, not the ID. Please replace ‘stormx’ with ‘storm’ and it should work. You can see a full list of coin names, IDs, and symbols by making a request to https://api.coingecko.com/api/v3/coins/list

      Reply
  11. Is there a volume to get data on 24h volume change? I see market cap change; would be nice to get volume changes as well?

    Reply
  12. Thanks for useful topic. I have one question. I want to know how to get latest import token or coin on coingecko ? Can you have any idea for this?

    Reply
  13. Hi there
    when I alter the cells for coin IDs on the ‘Input’ tab, it pulls the token name through but not the data to the Summary tab?

    Reply
  14. I get the following error when making a request. Rarely the request works but most of the times I get this error. Any help is appreciated

    809: unexpected token at '
    !--[if lt IE 7]> <![endif]-->
    !--[if IE 7]> <![endif]-->
    !--[if IE 8]> <![endif]-->
    !--[if gt IE 8]>>--> <!--

    Access denied | api.coingecko.com used Cloudflare to restrict access

    Reply
    • Hmm I haven’t come across this specific error before but CoinGecko writes about using Cloudflare here. On that page they write “However, occasionally there can be false positive situation where legitimate users may accidentally get flagged by Cloudflare. This can due to our security settings being too tight or incorrectly setup. It might also be because the user is making requests from an IP address pool that is deemed to be suspicious.”

      So it looks like they’ve erroneously flagged your request. You might need to contact their support or use a different crypto API that gives you a private key.

      Reply
    • Sorry, I don’t really understand your question, are you saying your requests work through a desktop browser but not through mobile, or something else?

      Reply
      • You mean you can’t open the add-on? The mobile version of Google Sheets doesn’t support add-ons, unfortunately we can’t do anything about that.

  15. Hey Ana, thanks for the tutorial. Quick question – I would like to include the 24H price change AND the 7 days price change of let’s say BTC. How should I change the following path?

    https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd&include_24hr_change=true

    Reply
    • Hi there, their /simple/price endpoint doesn’t support 7 days price change parameter. You can see all the parameters they support here: https://www.coingecko.com/en/api/documentation

      Based on that, only the /coins/markets endpoint enables 7 days price change, so you’d make your URL like this:
      https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin&order=market_cap_desc&per_page=100&page=1&sparkline=false&price_change_percentage=24h,7d

      Reply
  16. Hey love this tool. It’s pretty much perfect except it doesn’t seem to refresh data very much. After successfully refreshing once, I only get this error:

    Data: Request failed: Service invoked too many times for one day: urlfetch.

    Has Coingecko throttled the API or something recently?

    Thanks so much for this!

    Reply
    • Hey Rick, that’s an error message from Google Sheets itself, not from API Connector or CoinGecko. Google Sheets has a daily limit of 20,000 URL fetches (which includes API calls as well as functions like GOOGLEFINANCE). So it sounds like you’re running a massive number of queries and hitting Google’s limits. Assuming this isn’t on purpose, you probably need to reconfigure your setup so it doesn’t refresh so often. If you’re using the IMPORTAPI function, please check this article, the section on Excess Recalculation has some suggestions for avoiding the urlfetch error.

      Reply
      • Thanks. It was just using the API connector template form this article. I don’t get what I could be doing wrong. Even today it still gives the error. Hmmm… I’ll keep trying I guess.

      • That’s strange, the template can’t possibly run anywhere near 20K requests a day so I don’t think it’s related to that.
        Could you be running any other scripts or add-ons, or “urlfetch” functions like IMPORTRANGE or GOOGLEFINANCE?
        If you’re not sure where scripts are running, please check https://drive.google.com/drive/my-drive and click Recent to see which Sheets have recently refreshed. That might show you some auto-refreshing sheets you’ve forgotten about.

  17. hi Ana,
    thanks for the tutorial! however, I am wondering if it’s possible to pull the market cap of the coins at a specified time on a date? ex. I’d like to know the market cap of all coins on my list at 2pm on 2. Sep 2018.

    Reply
    • Hey, you can see all the data points provided by CoinGecko here: https://www.coingecko.com/en/api/documentation
      The /coins/{id}/history endpoint gives you historical data (name, price, market cap) for a given date, so you could run a request like https://api.coingecko.com/api/v3/coins/bitcoin/history?date=02-09-2018
      They don’t let you specify an hour though, so you might need to check out different crypto APIs for that.

      Reply

Leave a Reply to NKs Cancel reply

Table of Contents