Live coin prices can be incredibly useful for tracking the performance of your cryptocurrency investments directly in a spreadsheet.
Whether you're monitoring Bitcoin, Ethereum, or any other cryptocurrency, having real-time data allows for immediate decisions and analysis.
For instance, you could use this data to calculate your portfolio value in real time or set up alerts for when a coin reaches certain price thresholds.
Before you start, you'll need a Coinranking API key. Sign up and copy your API key. This key is essential for making requests to our API.
Open a new Google Sheets document where you want to display the live coin prices.
In your Google Sheet document, go to Extensions > Apps Script.
Delete any code in the script editor and paste the following code:
function getCoinPrice() {
// This is the UUID for Bitcoin, replace it with the coin you need
const coinUuid = 'Qwsogvtv82FCd'
const url = `https://api.coinranking.com/v2/coin/${coinUuid}`;
// Replace YOUR_API_KEY_HERE with your Coinranking API key
const apiKey = 'YOUR_API_KEY_HERE';
const options = {
method: 'get',
headers: {
'x-access-token': apiKey
}
};
const response = UrlFetchApp.fetch(url, options);
const json = response.getContentText();
const data = JSON.parse(json);
return data.data.coin.price;
}
Go back to your Google Sheet.
In the cell where you want to display the live price, enter =getCoinPrice() and press Enter.
To automatically refresh the price, we need to set up a time-driven trigger in Apps Script.
Now, decide when and how often you want your script to run.
You can select specific options like Hour timer for it to run every hour, or Day timer to run at a specific time each day, among others.
Optionally, you can set up notifications for when your script runs or if it fails by clicking on Notifications.
After setting everything up, click "Save". You might need to authorize your script to run under your account. Follow the prompts to allow permissions.
You've successfully set up your Google Sheets to display live cryptocurrency prices using Coinranking API.
This setup can be customized further to track multiple coins, calculate portfolio values, or even set up conditional formatting for visual alerts.
Remember, the Coinranking API offers a wealth of data beyond just live prices, so feel free to explore and expand your spreadsheet's capabilities.