Get your real-time Trade Balance from Kraken in Google Sheets

Eloise
Coinmonks
6 min readJan 12, 2021

--

Source: Kraken.com

This tool will be useful and fast for those who perform end of month accounting or use Google Sheets to value their cryptocurrency portfolio.

Kraken.com has already written the Google Sheet code for us. All we need to do is follow instruction from Kraken Google Script — REST API Private Endpoints.

NB before we go further: NEVER SHARE YOUR SHEETS WITH YOUR PRIVATE INFORMATION!

What you’ll need :

  • Generate Kraken private API keys (3min)
  • Open Google Sheet
  • Add code — Ctrl C/Ctrl V — Authorize — Save (3min)

How it works:

From Kraken’s website: How to generate an API key pair?

API keys are one of the components of API authentication, they are the API equivalent of a username and password.

API keys are required to call any of the private API methods, namely the account management, trading, and funding methods. API keys are not required to use the public API methods (the market data methods) as the public methods do not need access to a Kraken account.

Creating An API Key

  • Sign in to your Kraken account.
  • Click on your name in the upper-right corner of the page.
  • Click on “Security” and then “API”.
  • Click on the “Add key” button.

Configuring An API Key

API keys have several configuration options that must be setup before an API key can be used, notably the Key Description and Key Permissions.

Source: https://support.kraken.com/hc/en-us/articles/360000919966-How-to-generate-an-API-key-pair-

Key Description

The Key Description is essentially the name of the API key, and can be almost anything that you prefer, as long as the description is unique (different from the descriptions of any other API keys on the same account).

Key Permissions are very important! The less access permissions, the better the security.

For the purpose of retrieving your total balance, you will just give permission to:

  • Query Funds, which is required for the account management methods that query the account balance information, such as Balance and TradeBalance.

Using an API Key

API keys consist of a public/private key pair, both of which must be provided to the API client software. The key pair can then be copied and pasted as plain text directly into the API client code.

Source: https://support.kraken.com/hc/en-us/articles/360000919966-How-to-generate-an-API-key-pair-

Open Google Sheet

  • Go to sheets.google.com
  • Google Drive — Click New
  • Google Sheets and create from scratch or from a template.
Source: sheets.google.com

Add the code that Kraken created for Google Sheets

  1. Open the script editor via the Tools -> Script editor menu.
Source: Google Script Editor

2. Delete the default code that is shown (Select All then Delete/Backspace, for example).

3. Copy/Paste the Google Script API code (link) into the script editor.

Source: Copy/Paste code from https://support.kraken.com/hc/en-us/articles/360047262172-Google-Script-REST-API-Private-Endpoints

4. Update the example API key to use an API key from your Kraken account.

Source: https://support.kraken.com/hc/en-us/articles/360047262172-Google-Script-REST-API-Private-Endpoints

5. Save the Google Script Code via the File -> Save menu or the

6. Authorize Google Services -> Apps Script requires user authorization to access private data from built-in Google services or advanced Google services.

Top left: Authorization required Continue — — — Top Right: Chose the gmail account for running the code — — — Bottom Left: App isn’t verigied, go to advanced, go to the project name — — — Bottom Right: Allow access to your newly created project

Use Kraken’s built-in formulas

=KAPI_Private(“TEST”, “TradeBalance”, “asset=USD”)

The KAPI_Private() function returns the original JSON response from the API, such as the following for the above Balance endpoint example:

  • {“error”:[],”result”:{“eb”:”20.7858",”tb”:”19.4652",”m”:”0.0000",”n”:”0.0000",”c”:”0.0000",”v”:”0.0000",”e”:”19.4652",”mf”:”17.4652"}}

eb: Evaluated Balance in real-time, tb: Last Trade Balance, e:Equity, mf:Free Margin.

Try it out, but instead of putting “TEST”, insert your description key name.

In order to get your total real-time balance, you need to retrieve the eb value from the JSON. You will need to add this lines of code in the KAPI_Private function as follows:

if (endpoint == “TradeBalance”){api_data=JSON.parse(api_data).result.eb}

Insert the line after line 19.

Source: Script Editor Add line 20: if (endpoint == “TradeBalance”){api_data=JSON.parse(api_data).result.eb}

This line will parse the JSON format, into the evaluated balance (”result”:{“eb”:”20.7858"}) and you will get valuation the sheets as shown on the following example cell O2.

Google Sheet Example
=KAPI_Private(“……”, “TradeBalance”, “asset=USD”)

Voilà! Now you should get your real-time Kraken balance. If you refresh the cell, you will get the latest amount. Cells usually refresh once every hour or so in Google Sheet.

More Tools

If you are interested in more cryptocurrency portfolio valuation tools, you might be interested by the following medium.

This is ongoing work. If you find errors, please do not hesitate to let me know. Feedback is very welcomed. A telegram chat is also available for support. If this project adds any value to you and/or are looking for personalized coding on your Google Sheets, don’t hesitate to leave a message.

The opinions expressed are for general informational purposes only and are not intended to provide specific advice or recommendations for any individual or on any specific security or investment product. It is only intended to provide education about the financial industry.

Thank you so much for investing your time in reading this article.

Take care of yourself & your family in these challenging times! Happy New Year 2021!

Join Coinmonks Telegram group and learn about crypto trading and investing

Also, Read

Get Best Software Deals Directly In Your Inbox

--

--