Select Page

You’re a crypto HODLer and you created a spreadsheet of all the cryptocurrencies, tokens and coins you own in a Google Sheet. On top of this, you want to see the latest price and dollar value of each cryptocurrency then later on create a chart to know the allocation of each crypto in your crypto portfolio. This tutorial will help you accomplish this goal.

Step 1. Create a spreadsheet in Google Sheet with Column A as the Crypto ticker and Column B as the number of units you have of each crypto.

Step 2. From the menu, select Tools -> Script Editor

Step 3. A new tab will open with the below Untitled project

Change the function code. You may paste the below script that calls Bitmex API. Feel free to change the API call if Bitmex does not return the price of your cryptocurrencies.

function getCryptoPrice(quote) {
   var price = 0
   
   if (quote != null) {
      var url = "https://www.bitmex.com/api/v1/trade?symbol="+quote+"&count=1&reverse=true"
      var response = UrlFetchApp.fetch(url);
      var jsonResponse = JSON.parse(response)
      price = jsonResponse[0].price
   }
  Logger.log(quote + " " +price)

  return price
}

Step 4. Now return to your Google sheet. Type in =getCryptoPrice(A2) with A2 being the cell where you want to query the current price of.

Step 5. Copy the function call in cell C2 to the rest of the cells in Column C by dragging from the lower right portion of the cell.

The cells will be populated with real-time prices for each crypto.

Now you accomplish your goal of getting real-time price in your Google Sheet.

Since you already have this information, why not get the current value of your cryptocurrencies and display the allocation in a pie chart? Continue the following steps:

Step 6. Now compute for the dollar value of your crypto at the current price.

Step 7. Highlight the 4 columns. Click Insert -> Chart

Step 8. By default, the chart type is Column chart. Click on the Column chart drop-down and choose Pie.

Step 9. Select the Chart. In Chart editor, click Setup tab. In the Label, choose Crypto column and in Label, choose Value $

References