How to keep track of your crypto-networth automatically using google sheets and Debank API

Yong kang Chia
BLOCK6
Published in
4 min readNov 5, 2021

It’s so hard to keep track of your crypto networth and PNL in one place. Sure there are apps out there, but there are none to put it all in one place, that's why many of us use google sheets.

The question is how do you keep your networth updated automatically on google sheets? Luckily Debank has an API for us that allows us to update our networth automatically and keep track of our networth.

In this tutorial, I will go over how we can write scripts to save the data automatically using Debank every single day.

Step 1 :

Create a new google sheet that you want to use to keep track of your portfolio.

Step 2:

Copy your metamask address and replace <address> with it

Debank URL : https://openapi.debank.com/v1/user/total_balance?id=<address>

For example:

address = 0x5853ed4f26a3fcea565b3fbc698bb19cdf6deb85
url = https://openapi.debank.com/v1/user/total_balance?id=0x5853ed4f26a3fcea565b3fbc698bb19cdf6deb85

Step 3:

Go back to your google sheets and click on tools > script editor and it should bring you to a new page like the one below

click on tools

You should see this page.

function myfunction(){} is a function where we can input our scripts

Step 4:

Create scripts for getting networth.

Copy the code below and replace everything in your Code.gs file.

// custom menu functionfunction onOpen() {var ui = SpreadsheetApp.getUi();ui.createMenu('Custom Menu').addItem('Save Data','saveData').addToUi();}function getNetworth() {var response = UrlFetchApp.fetch("https://openapi.debank.com/v1/user/total_balance?id=0x5853ed4f26a3fcea565b3fbc698bb19cdf6deb85");var data = JSON.parse(response.getContentText())// Logger.log(data.total_usd_value);return data.total_usd_value}// function to save datafunction saveData() {var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");var networth = getNetworth()console.log(networth)var date = Utilities.formatDate(new Date(), "GMT+1", "dd/MM/yyyy")sheet.appendRow([date,networth]);}

Remember your URL from step 2? Now replace the URL in UrlFetchApp.fetch(“https://openapi.debank.com/v1/user/total_balance?id=<address>") with the URL that you have

Step 5:

Now save your script by typing ctrl + s or hitting the save button.

Click run on the toolbar and review permissions.

Log in and accept it.

You might face authentication issues. Go ahead and allow it

Go back and refresh your sheet.

You should see the custom menu button

Click on the custom menu button and you should see save data. Go ahead and save the data.

Click on the save data and VOILA! Your pnl and date have been shown here!

Step 6:

So how do we automate it to trigger every day even while we are asleep?

Go back to your script editor. its tools > script editor

Next click on the trigger button. In my version its the clock icon.

Now click on add trigger at the bottom right.

Change select event source to be time-driven. The timer can be changed to daily or anything you want.

this is how it should look like

Click on Save and you are done! You now have your automated portfolio tracker.

what can you do with it?

  • create a historical profit and loss tracker
  • Add in coingecko API and find the individual items in your portfolio

Since this is the first part, I would not go in-depth into getting every single item from your portfolio, i.e those in LP or lending/borrowing protocols.

If you enjoy reading and would want to read more, signal it by applause!

Thank you for your time. Leave any feedback down there. More than welcomed! Have a great day

References

Debank: https://debank.com/

Debank API: https://debankopenapi.medium.com/

Contents distributed by Learn.Block6.tech

👉 Discord — Live Talks

👉 Twitter — Latest articles

👉 LinkTr.ee

--

--

Yong kang Chia
BLOCK6
Writer for

Blockchain Developer. Chainlink Ex Spartan Group, Ex Netherminds