A collection of Google Apps Script custom functions for tracking crypto portfolios in Google Sheets.
The price data is pulled using CoinGecko's API, and the token balances are obtained by making queries to various RPC servers like PublicNode.
If this project helped you, consider buying me a coffee via 3Cities or GitHub Sponsors.
- Obtain a CoinGecko Demo API by following the instructions here.
- Open the Cryptfolio template in Google Sheets.
- Click on "File", and then "Make a copy". This will create a copy of the template in Google Sheets.
- From the toolbar, click on "Extensions", and then on "Apps Script". You should be able to see the code now.
- Add the chains and tokens you want to track in the
ChainIdandTokenobjects indata.gs. - Query the price data by running the
GET_ALL_PRICESfunction. - Use the
GET_ERC20_BALANCEandGET_NATIVE_BALANCEfunctions to query your holdings in real-time. - Calculate the USD value of your holdings by reading the local price data with
INDEXandMATCH.
Note
The GET_ALL_PRICES can only be run from within Apps Script. See the Custom Functions section
below.
The template shows how to query balances for ARB, ETH, MKR, and OP, and how to calculate the values of the holdings:
I built this because I was frustrated with the existing solutions, which are either too complex, too expensive, or too unstable.
Cryptfolio is:
- Free to use
- Minimalist
- DYI and easy to customize
- Functional; it just works
This project is meant to be forked and customized to your needs. Here are two common use cases:
To track a new chain:
- Add it to the
ChainIdobject indata.gs. - Add the corresponding RPC URL to the
RpcUrlobject. - Optionally add chain name mappings to the
ChainNameMapobject for easier reference.
To track a new token:
- List it in the
Data:Pricessheet in the spreadsheet. Ensure that theCOIN_IDSrange got updated, too. - Add the token to the
Tokenobject indata.gswith its contract address and decimals. - For multi-chain tokens, use the chain-specific structure (see examples like
USDCorDAI).
Here's a table with the custom functions enabled by this project.
The Read functions can be called from either Google Sheets or Apps Script, but the Write functions can only be run from within the Apps Script environment. This is because a custom function cannot affect cells other than those it returns a value to.
| Function | Type | Params | Description |
|---|---|---|---|
GET_ERC20_BALANCE |
Read | (chain,symbol,account) | Get the ERC-20 token balance of account on the specified chain |
GET_NATIVE_BALANCE |
Read | (chain,account) | Get the native asset balance of account on the specified chain |
GET_ALL_PRICES |
Write | (fiat) | Get the current fiat prices for all COIN_IDS |
GET_PRICE |
Write | (coinId,fiat) | Get the current fiat price for coinId |
Feel free to dive in! Open an issue, start a discussion or submit a PR.
This project couldn't exist without the CoinGecko API. Thank you for providing such a valuable service for free!
This project is licensed under MIT.