How To Track Crypto Portfolio On Google Sheets Using Coingecko API

crypto portfolio.png

Now, this is something I learned recently so I thought of making it into a post for those that don't know how to do it and interested in making an excel for their crypto portfolio. I've been wanting to make a portfolio for my crypto on an excel sheet and I finally got to it with some help because my coding kind of sucks. I luckily have a friend on discord that taught me how to set this up. Now I'm going to make it easy for you as I give you a step by step process on how to do this.


Step 1 - Have a Google Sheet Ready

image.png

You can set up the Hive and HBD there and any other crypto you want to add.


Step 2 - Create Demo Account & Get An API Key

image.png

You have to create a demo account and get an API Key. You can go to "https://www.coingecko.com/en/api/pricing" and this will take you to the page for the photo above. Then you can get your API key from "https://www.coingecko.com/en/developers/dashboard" after you created an account you can add a new key I believe or there will be one there already.

image.png


Step 3 - Go Back To Excel and Go to Apps Script

image.png


Step 4 - Add Script

image.png

Now all you have to do is copy and paste the following code into the script (starting from function to the } and edit accordingly to your api key, name of the sheet and the cell you want for the price to show up. Make sure to remove the brackets after editing. Below I have given the script code for Hive and HBD.

If you want to do different crypto, you have to edit the apiURL and the part after the setCryptocurrencyPriceInSheet(hive) and getCoinGeckoTicker(hive) and return data["hive"]. You will need to change the hive to whatever crypto name it is. If the crypto has more than one word in the name make sure to add the hyphen or underscore. You can see HBD has hive_dollar. The list of the apiurl for the tokens and for the names to change can be taken from here https://api.coingecko.com/api/v3/coins/list


Hive

function getCoinGeckoTickerhive() {
var apiKey = "[YOUR API KEY HERE]";
var apiUrl = "https://api.coingecko.com/api/v3/simple/price?ids=hive&vs_currencies=usd";

var headers = {
"x-cg-demo-api-key": apiKey
};

var response = UrlFetchApp.fetch(apiUrl, {headers: headers});
var data = JSON.parse(response.getContentText());

return data["hive"].usd;
}

function setCryptocurrencyPriceInSheethive() {
// Replace '0.05' with the result from your existing function.
var cryptocurrencyPrice = getCoinGeckoTickerhive();

// Access the "Sales summary" sheet and set the price in cell G1.
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName("[Sheet Name]");
sheet.getRange("D6").setValue(cryptocurrencyPrice);
}


HBD

function getCoinGeckoTickerhivedollar() {
var apiKey = "[YOUR API KEY HERE]";
var apiUrl = "https://api.coingecko.com/api/v3/simple/price?ids=hive_dollar&vs_currencies=usd";

var headers = {
"x-cg-demo-api-key": apiKey
};

var response = UrlFetchApp.fetch(apiUrl, {headers: headers});
var data = JSON.parse(response.getContentText());

return data["hive_dollar"].usd;
}

function setCryptocurrencyPriceInSheethivedollar() {
// Replace '0.05' with the result from your existing function.
var cryptocurrencyPrice = getCoinGeckoTickerhivedollar();

// Access the "Sales summary" sheet and set the price in cell G1.
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName("[Sheet Name]");
sheet.getRange("D7").setValue(cryptocurrencyPrice);
}


Step 5 - Run The Script

image.png

image.png

Run the script and make sure you have setCryptocurrency and not get coingeckoticker if not you might get an error.

If everything is done right, it should show up below in the cell designated.

image.png


Bonus Step - Trigger Update Price

Now this is not necessary but is nice to have. If you don't want to keep running the script, to get an updated price there's a way to trigger it.

image.png

image.png

When you add a trigger, make sure it's time-driven and the correction function. After that you can choose how often you want it to run. Since you are using a demo account, it's not ideal to have it update by minute you would hit the limit for the free plan. I suggest every 12 hours. Personally I set it to by day but that's up to you.


I hope this helps. If you have any issues, find me on discord or drop some comments. I'll do my best to help!

Posted Using InLeo Alpha



0
0
0.000
14 comments
avatar

That's helpful to know. GG.

0
0
0.000
avatar

O.O how do you track yours?

0
0
0.000
avatar

i dont have much to track 😅

0
0
0.000
avatar

oh o.o cuz i totaling everything including nfts o.o. aiming to hit total 1 million . so ig uess for end of this year maybe 150k. then next 350k and next 500k then i can hit my first million before 30 but who knows maybe can get it before then

0
0
0.000
avatar

gg man! looking forward to seeing you smash this!!

0
0
0.000
avatar

YES lets do it haha. or wait you already a whale :p

0
0
0.000
avatar

I never knew about this until you make a post about this
Very educational

0
0
0.000
avatar

hey maybe you can try it if you have enough crypto to keep track of. now I need to figure out how to get the data from opensea lol so i can get some of the nfts as well autoset

0
0
0.000
avatar

Ini bagus

0
0
0.000
avatar

haha the script a friend gave me if not I won't know how to do this. I tried so many times using coinmarketcap api. importxml and other stuff but failed. only the googlefinance trick worked but it doesn't have all the tokens I wanted

0
0
0.000
avatar

This post has been manually curated by @alokkumar121 from Indiaunited community. Join us on our Discord Server.

Do you know that you can earn a passive income by delegating your Leo power to @india-leo account? We share 100 % of the curation rewards with the delegators.

100% of the rewards from this comment goes to the curator for their manual curation efforts. Please encourage the curator @alokkumar121 by upvoting this comment and support the community by voting the posts made by @indiaunited.

0
0
0.000
avatar

This post has been manually curated by @alokkumar121 from Indiaunited community. Join us on our Discord Server.

Do you know that you can earn a passive income by delegating to @indiaunited. We share more than 100 % of the curation rewards with the delegators in the form of IUC tokens. HP delegators and IUC token holders also get upto 20% additional vote weight.

Here are some handy links for delegations: 100HP, 250HP, 500HP, 1000HP.

image.png

100% of the rewards from this comment goes to the curator for their manual curation efforts. Please encourage the curator @alokkumar121 by upvoting this comment and support the community by voting the posts made by @indiaunited.

0
0
0.000