Source Link: https://algotrading101.com/learn/kraken-api-guide/
Kraken is one of the market’s most reliable and established crypto exchanges today. Established in 2011, Kraken is now valued at $11 billion as of 2022. If you are new to this cryptocurrency, this article will show you everything about Kraken API.
Kraken API: The Basics
Before going to the how-to’s of Kraken API, let’s first learn the basics – What is Kraken? What is Kraken API? Is it free? What are the advantages and disadvantages of using Kraken?
What is Kraken?
Kraken is one of the most trusted and popular US-based online cryptocurrency exchange platforms that allow traders to trade more than 50 coins and tokens. This platform also features OTC, Fiat, futures, spot, and margin trading.
What is Kraken API?
Kraken API refers to the method that allows traders to automatically trade crypto coins and tokens on Kraken using codes.
The Kraken API is available in many countries worldwide, but there are a few countries where using Kraken API is not possible. These countries include Afghanistan, Iran, Cuba, Iraq, Japan, Tajikistan, and North Korea.
Available clients for the Kraken API are the following:
Can I use Kraken API for free?
It is free to create a Kraken account and use the Kraken API. However, when you trade, there are fees that you need to keep in mind. These fees vary depending on the assets you are trading, trading volume, the platform you are using, and more.
There are five types of fee schedules when you trade on Kraken – Instant Buy, Kraken Pro, Stablecoin $ FX Pairs, Margin, and Futures.
This fee schedule allows traders to buy, sell and convert Bitcoins and other cryptos using the Kraken app. A 0.9% fee is issued if you are buying stablecoins with USD or other stablecoins. A 1.5% fee is issued if you are buying a stablecoin with another cryptocurrency.
This fee makes use of the maker-taker fee system with volume incentives that take into account your activity for the past 30 days. Because fees are calculated as a percentage of the trade’s currency volume, the more you trade, the lower the fees will be. The fees are as follows:
Stablecoin $ FX Pairs
This fee applies to FX pairs where a stablecoin is the base currency. The fee schedule is as follows:
The Margin fee is the added trading fee you need to pay at the opening and closing of margin positions. Here are the fees:
This follows the maker-taker fee system where the previous non-futures orders are not included. The fee schedule are as follows:
Reasons to use Kraken API
Here are the reasons why you should use Kraken API:
- It is free to use
- It is easy to use, especially for beginners
- Fees are reasonable
- Had decent API
- Good track record
- Great selection of assets
- It is customizable
Reasons NOT to use Kraken API
Here are the reasons why you should NOT use the Kraken API:
- Slow customer support
- Does not have a test option
- It requires ID verification
How To Get Started: Kraken API Guide
First things first. Here is the step-by-step guide to using the Kraken API.
To create an account, click the “Create Account” button. It will require you to input your email address, desired username and password, and country of residence.
After creating an account, you will receive an email asking you to confirm your account activation.
Obtain API Key
Once the account activation is done, you will be taken to the main website.
Click on your name in the upper right corner and then go to security and API.
Click on Add Key and indicate what your API Key is allowed to do.
Generate API Key and safely keep your keys as the Private Key will no longer be visible after you close the window.
Install the Kraken API
To install it, use the following command:
How to Get Asset Info
You can obtain the available assets through the API using this function:
Another option to do it is by using this function:
Obtain tradable assets using this function:
How to Get Price Data
Obtain the price data from Kraken API using this function:
Here’s a quick guide to the responses:
- index = pair name
- a = ask array(<price>, <whole lot volume>, <lot volume>)
- b = bid array(<price>, <whole lot volume>, <lot volume>)
- c = last trade closed array(<price>, <lot volume>)
- h = high array(<today>, <last 24 hours>)
- l = low array(<today>, <last 24 hours>)
- o = today’s opening price
- p = volume weighted average price array(<today>, <last 24 hours>)
- t = number of trades array(<today>, <last 24 hours>)
- v = volume array(<today>, <last 24 hours>)
How to Get Historical Data
You can successfully obtain historical data using this function:
How to Access Technical Indicators
Here is how to access technical indicators such as the 20 SMA (Simple Moving Average) with the Kraken API:
Once you got the data, you can create the chart using this:
How to Get Order Book Data
You can obtain the order book data using the function shown below. Remember, the depth of the order book can go up to 100.
You can also merge two sub-datasets (bids and asks) by their index value. Just use this:
How to Execute a Trade on ETH when BTC Hits a Certain Price
Here is how to properly and securely launch and order following specific requirements. The objective is to launch a trade on ETH when BTC hits a certain price.
In order for this trade to work, you need to set an order foundation and create a loop that will check the price. If the price is hit, you execute a market order. If not, continue looping around.
Notice the kraken.load_key part – it loads the text file where you need to store your API Key and API Secret on separate lines.
Here’s how to create the full loop:
If you need help, just type this command:
How to Execute an ETH Trade when BTC Moves 5% in the Last 5 Minutes
So, the goal is to execute an ETH trade when BTC movies 5% in the last five minutes. If the percentage change is less than 5%, the program will sleep for five minutes and then do the recalculation. The trade will execute if the percentage is equal to or more than five.
Here’s how you code it:
How to Cancel Orders
If you want to cancel orders with Kraken API, here’s the code:
How to use Kraken API in Google Sheets
You can use Kraken API in Google Sheets using the API Connector add-on. You can download it from the Google Workspace Marketplace.
Once you install the add-on, here’s what you need to do:
Open up a Google spreadsheet and go to Add-ons, then API Connector, then click Open.
After the API Connector interface opens up, click the “Create” button and write your HTTP request in the API URL path.
Plug in the Kraken API assets URL set the destination sheet to current, and, under Output options, set the Report Style to compact.
Let’s give the request a name and click “Run” to see what the output looks like:
You need to transpose the output in Excel. Click on the first asset and then run the Shift + Ctrl + Right arrow key shortcut to select all the assets.
Click on a new cell where you want to transpose the outputs (in this case, the error cell) and then right-click, then Paste special, then Paste transposed.
You can also try out some other endpoints like the following:
You can access the full code on this GitHub Link.
want to learn how to algo trade so you can remove all emotions from trading and automate it 100%? click below to join the free discord and then join the bootcamp to get started today.