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:
- A Google account (to access Google Sheets)
- A CoinMarketCap API key (free tier available)
Step-by-Step Guide to Import Crypto Prices
Step 1: Add the Script to Google Sheets
- Open a new Google Sheet.
- Navigate to Extensions > Apps Script.
- 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;
}
}- Save the project as
GETCRYPTOPRICE.
Step 2: Obtain Your CoinMarketCap API Key
- Visit ๐ CoinMarketCap API Portal
- Sign up and copy your API key from the dashboard.
Step 3: Integrate the API Key
- Replace
YOUR_API_KEYin the script with your actual key (e.g.,"123abc-456-def"). - Save the script again.
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
- Auto-Refresh: Set triggers under "Edit > Current project's triggers" to update prices periodically.
- Multi-Currency Support: Use formulas like
=GETCRYPTOPRICE("ETH", "EUR")for European markets.
FAQs
Why is my GETCRYPTOPRICE function returning an error?
Common causes include:
- Invalid API key (recheck Step 2)
- Incorrect ticker symbol (e.g., use "BTC" instead of "Bitcoin")
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:
- Monitor real-time crypto prices
- Automate portfolio tracking
- Analyze trends without leaving Google Sheets