How to Import Crypto Prices in Google Sheets

ยท

Tracking cryptocurrency prices efficiently can streamline your portfolio management. This guide will show you how to display real-time crypto prices directly in Google Sheets using a custom function.

Prerequisites

Before starting, ensure you have:

Step-by-Step Guide to Import Crypto Prices

Step 1: Add the Script to Google Sheets

  1. Open a new Google Sheet.
  2. Navigate to Extensions > Apps Script.
  3. Replace the default code with this script:
const CMC_PRO_API_KEY = "YOUR_API_KEY";
function GETCRYPTOPRICE(ticker, currency) {
  try {
    const res = UrlFetchApp.fetch(`https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=${ticker}&convert=${currency}&CMC_PRO_API_KEY=${CMC_PRO_API_KEY}`);
    const content = res.getContentText();
    const json = JSON.parse(content);
    return json.data[ticker.toString()].quote[currency.toString()].price;
  }
  catch (err) {
    return "Error: " + err.message;
  }
}
  1. Save the project as GETCRYPTOPRICE.

Step 2: Obtain Your CoinMarketCap API Key

  1. Visit ๐Ÿ‘‰ CoinMarketCap API Portal
  2. Sign up and copy your API key from the dashboard.

Step 3: Integrate the API Key

Step 4: Use the Function in Your Sheet

Enter this formula in any cell:
=GETCRYPTOPRICE("BTC", "USD")
Replace BTC and USD with your preferred cryptocurrency and fiat currency.


Advanced Tips


FAQs

Why is my GETCRYPTOPRICE function returning an error?

Common causes include:

Can I track multiple cryptocurrencies simultaneously?

Yes! Create separate cells with different tickers (e.g., =GETCRYPTOPRICE("SOL", "GBP")).

Is there a rate limit for the API?

CoinMarketCap's free tier allows ~10,000 monthly calls. Monitor usage ๐Ÿ‘‰ here.


Conclusion

With this setup, you can now: