This is a simple script that provides a formula to retrieve the price of a crypto and a menu with a button to update all the formulas at once.
To avoid hitting the CoinMarketCap free plan limits, adding each individual formula does not make a request, but instead displays a dummy text in the formula value.
When you have finished adding all the formulas, click the update button on the menu and a single request is made to retrieve all the prices and update the formulas.
Use this formula where you want to retrieve the price of a crypto.
=CMCPRICE("KUMA")
By default it displays a text before fetching the price from the API, if you are using it within a more complex formula and you don't want to trigger an error, you can add a temporary value, it will be updated later.
=CMCPRICE("KUMA", 1)
After placing all the formulas, just go to the menú and click on "CoinMarketCap" > "Update".
- At the menu, navigate to "Extensions" > "Apps Script".
- Set a name for the project, optionally you can also rename the script file.
- Copy all the content of
Code.gs
and paste it on the script editor.- If you already have other scripts with the
onOpen ()
function, copy the contents of the one of this script, remove the function, and paste it into the other one.
- If you already have other scripts with the
- Put your CoinMarketCap API KEY in the
API_KEY
variable, if you don't have one, get yours on their website. - Save the project with the save button or with
CTRL + S
/CMD + S
. - Come back to the sheet and refresh the page.
- Place all the formulas you want.
- Go to the menu and click on "CoinMarketCap" > "Update".
- A pop-up appears asking for permission to run the script.
- Click on "Continue", then choose the Google account that created the sheet.
- Click on "Advance" at the bottom, then on "Go to PROJECT NAME (unsafe)" and finally on "Allow".
- Go to the menu again and click on "CoinMarketCap" > "Update".