Predictive Hacks

How to Get Cryptocurrency Data from Kraken API in Python


Data Scientists can be involved in “algorithmic trading” projects. Currently, since we are entering the Web3 era, we come across terms such as Blockchains, Smart Contracts, DeFi, DApps, DAO, Yield Farming and so on. All these things that we mentioned above are based on blockchain technology and cryptocurrencies. As a result, it seems that cryptocurrencies do not serve only as a medium to transfer money, but also as a promising revolutionary technology with many applications. Many strong players like Microsoft, IMB etc have started investing in Web3 and this interest impacts the cryptocurrency market. More investors and funds enter the cryptocurrency market and there is a higher demand for Data Scientists to run technical analysis, statistical analysis, time series model, algorithmic trading and so on. As we know, every analysis starts with the data and in this tutorial, we will show you how to get the cryptocurrency data from Kraken API using Python for free without needing to create an account.

How to Get the Trading Pairs

The first thing that we need to do is to get the available trading pairs and then filter them by keeping the ones that we want to consider in our analysis. Let’s say that we want to consider all the cryptocurrencies over Euro:

import pandas as pd
import requests

resp = requests.get('')

resp = resp.json()

euro_pairs = []
for pair in resp['result']:
    if pair.endswith('EUR'):


We get 125 crypto tickers len(euro_pairs):



We can get an output of a specific asset pair by entering the pair variable in the URL. Let’s get the asset pair ADA/EURO.

resp = requests.get('')


{'error': [],
 'result': {'ADAEUR': {'altname': 'ADAEUR',
   'wsname': 'ADA/EUR',
   'aclass_base': 'currency',
   'base': 'ADA',
   'aclass_quote': 'currency',
   'quote': 'ZEUR',
   'lot': 'unit',
   'pair_decimals': 6,
   'lot_decimals': 8,
   'lot_multiplier': 1,
   'leverage_buy': [2, 3],
   'leverage_sell': [2, 3],
   'fees': [[0, 0.26],
    [50000, 0.24],
    [100000, 0.22],
    [250000, 0.2],
    [500000, 0.18],
    [1000000, 0.16],
    [2500000, 0.14],
    [5000000, 0.12],
    [10000000, 0.1]],
   'fees_maker': [[0, 0.16],
    [50000, 0.14],
    [100000, 0.12],
    [250000, 0.1],
    [500000, 0.08],
    [1000000, 0.06],
    [2500000, 0.04],
    [5000000, 0.02],
    [10000000, 0.0]],
   'fee_volume_currency': 'ZUSD',
   'margin_call': 80,
   'margin_stop': 40,
   'ordermin': '2.5'}}}

We can add more pairs to the same call by adding the required pairs in the URL separated by a comma. For example, if we want the ADA/EURO and AAVE/EUR:

resp = requests.get(',AAVEEUR')


{'error': [], 'result': {'AAVEEUR': {'altname': 'AAVEEUR', 'wsname': 'AAVE/EUR', 'aclass_base': 'currency', 'base': 'AAVE', 'aclass_quote': 'currency', 'quote': 'ZEUR', 'lot': 'unit', 'pair_decimals': 2, 'lot_decimals': 8, 'lot_multiplier': 1, 'leverage_buy': [2, 3], 'leverage_sell': [2, 3], 'fees': [[0, 0.26], [50000, 0.24], [100000, 0.22], [250000, 0.2], [500000, 0.18], [1000000, 0.16], [2500000, 0.14], [5000000, 0.12], [10000000, 0.1]], 'fees_maker': [[0, 0.16], [50000, 0.14], [100000, 0.12], [250000, 0.1], [500000, 0.08], [1000000, 0.06], [2500000, 0.04], [5000000, 0.02], [10000000, 0.0]], 'fee_volume_currency': 'ZUSD', 'margin_call': 80, 'margin_stop': 40, 'ordermin': '0.02'}, 'ADAEUR': {'altname': 'ADAEUR', 'wsname': 'ADA/EUR', 'aclass_base': 'currency', 'base': 'ADA', 'aclass_quote': 'currency', 'quote': 'ZEUR', 'lot': 'unit', 'pair_decimals': 6, 'lot_decimals': 8, 'lot_multiplier': 1, 'leverage_buy': [2, 3], 'leverage_sell': [2, 3], 'fees': [[0, 0.26], [50000, 0.24], [100000, 0.22], [250000, 0.2], [500000, 0.18], [1000000, 0.16], [2500000, 0.14], [5000000, 0.12], [10000000, 0.1]], 'fees_maker': [[0, 0.16], [50000, 0.14], [100000, 0.12], [250000, 0.1], [500000, 0.08], [1000000, 0.06], [2500000, 0.04], [5000000, 0.02], [10000000, 0.0]], 'fee_volume_currency': 'ZUSD', 'margin_call': 80, 'margin_stop': 40, 'ordermin': '2.5'}}}

How to Get all the Assets

We can get a list of all the available assets by running:

resp = requests.get('')
resp = resp.json()

assets = []
for asset in resp['result']:


We get 156 assets:


How to Get the Current Price of a Ticker

We can get the current market prices for an individual currency pair, and includes all the following information:

  • most recently traded price
  • most recently traded volume
  • best (highest) bid price
  • volume available at best bid price
  • best (lowest) ask price
  • volume available at best ask price
  • additional trading information (high/low of day, number of trades, total volume of day, etc.)

Note: Today’s prices start at midnight UTC

Let’s get the current ticker data of the ADA/EUR

resp = requests.get('')



{'error': [],
 'result': {'ADAEUR': {'a': ['0.794935', '850', '850.000'],
   'b': ['0.794734', '850', '850.000'],
   'c': ['0.794997', '100.00000000'],
   'v': ['1057413.14777778', '2846333.33727160'],
   'p': ['0.785368', '0.776113'],
   't': [1607, 3526],
   'l': ['0.769807', '0.755176'],
   'h': ['0.800000', '0.800000'],
   'o': '0.770461'}}}

How to Get OHLC Data

Now, we will show you how to get the OHLC data of a cryptocurrency. In the URL, you can define the interval in minutes and the starting period in Unix timestamp. Let’s say that we want to get the hourly data of ADA/EUR from 2022-19-03 up to now. Notice that the API returns the following statistics:

  • Unix Timestamp
  • Open Price
  • High Price
  • Low Price
  • Close Price
  • Volume Weighted Average Price (vwap)
  • Volume
  • Number of transactions
resp = requests.get('')

df = pd.DataFrame(resp.json()['result']['ADAEUR'])
df.columns = ['unixtimestap', 'open', 'high', 'low', 'close', 'vwap', 'volume', 'count']


If we want to get a quick plot:

import matplotlib.pyplot as plt
%matplotlib inline


If we want to build a pipeline to add more cryptocurrencies with a for loop, we can work as follows. For simplicity, let’s consider only two cryptocurrencies, the ADA and the AAVEX over Euro.

df = pd.DataFrame()
my_pairs = ['ADAEUR','AAVEEUR']

for pair in my_pairs:
    tmp_url = f'{pair}&since=1647625329&interval=60'.format(pair)
    resp = requests.get(tmp_url)
    tmp_df = pd.DataFrame(resp.json()['result'][pair])
    tmp_df['asset'] = pair
    df = pd.concat([df,tmp_df])

df.columns = ['unixtimestap', 'open', 'high', 'low', 'close', 'vwap', 'volume', 'count', 'asset']  

Final Thoughts

As Predictive Hacks, we never claimed that we can predict the market and more specifically the cryptocurrency market, which is so volatile. However, we can assess the risks, the implied volatility, ideas of how to build optimized portfolios, how to run technical analysis and many other things. We believe that there will be a high demand for cryptocurrency analysis and this is a good opportunity for the Data Scientists since there will be many investors that would like to apply algorithmic trading, dashboards, analysis, reports and so on. So, I do not know if you can make money by investing in the cryptocurrency market but I strongly believe that you can make money from the cryptocurrency demand working as Data Scientist. Stay tuned for the next tutorials!

Want some Free Cryptos?

You can get $25 in Bitcoin by investing $100 in Nexo

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

2 thoughts on “How to Get Cryptocurrency Data from Kraken API in Python”

  1. How can you distinguish between cryptocurrency and traditional currencies from the data you are fetching???? They are all labeled “currency”!


Leave a Comment

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore


Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.


Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s