Understanding the Kraken Trades API: A Guide to Building Historical Data
As a trader or analyst, access to reliable and accurate historical data is essential for making informed decisions about your investments. However, when it comes to trading platforms like Kraken, providing such data can be a significant challenge. In this article, we will explore the Kraken Trades API, which allows users to access historical trading data using an open-source Python library.
Why is historical data needed?
Historical data is important for several reasons:
- To analyze price movements and identify trends
- To set buy and sell signals based on market conditions
- To optimize trading strategies
Without reliable historical data, it can be difficult to make accurate predictions about future market movements.
Kraken Trades API: Getting Started
To start building your own historical OHLC data from Kraken trades, you will need to follow these steps:
- Register an Account: Create a free account on the Kraken website.
- Get API Access: Register for a developer account on the Kraken Trades API page and obtain your API credentials.
Using the Kraken Trades API with Python
Once you have access to your API credentials, you can start building historical data using the following steps:
Step 1: Install the required libraries
To use the Kraken Trades API with Python, you will need to install the requests
library for making HTTP requests and the pandas
library for manipulating data.
pip install pandas requests
Step 2: Set up your API connection
Create a new file called kraken_trades.py
and add the following code:
import requests
import pandas as pd

Set up your Kraken Trades API credentialsapi_key = 'YOUR_API_KEY'
api_secret = 'YOUR_API_SECRET'
Set up your API endpointendpoint = f'
Send a GET request to the API endpointresponse = requests.get(endpoint)
Check if the response was successfulif response.status_code == 200:
Parse the JSON response into a DataFramedf = pd.json_normalize(response.json())
return df
else:
print(f'Error: {response.text}')
return None
Step 3: Filter and Clean the Data
After you receive the data, you will need to filter and clean it before importing it into your desired data format.
Filter out any invalid or missing datadf = df[df['time'] > 0]
Convert the 'open' column to a numeric type (float) if possibledf['open'] = pd.to_numeric(df['open'])
Step 4: Save and Export the Data
You can now save the cleaned and filtered DataFrame into your desired file format.
import pickle
Save the DataFrame to a Pickle filewith open('kraken_trades.pkl', 'wb') as f:
pickle.dump(df, f)
Usage Example
Here is an example of how you can use this code to produce historical OHLC data from Kraken trades:
«`python
import kraken_trades
Get your API credentials
api_key = ‘YOUR_API_KEY’
api_secret = ‘YOUR_API_SECRET’
Set the API endpoint
endpoint = f’
Send a GET request to the API endpoint and parse the response as a DataFrame
df = kraken_trades.get_trades_dataframe(endpoint)
Filter out any invalid or missing data
df = df[df[‘time’] > 0]
Convert the ‘open’ column to a numeric type (float) if possible
df[‘open’] = pd.to_numeric(df[‘open’])
Save and export the DataFrame to a Pickle file
with open(‘kraken_trades.pkl’, ‘wb’) as f:
pickle.