In Australia, Beaufort Fiduciaries Pty Ltd (ACN 162 139 871, AFSL No. 545124) provides wholesale clients with access to derivatives where the underlying assets are digital assets. Derivatives are complex, regulated financial products that are difficult to understand and may not be suitable for inexperienced investors. For eligibility, terms and conditions click here. Krak Pay is offered by Bit Trade Australia Pty Ltd (ACN 163 237 634), Authorised Representative of Flexewallet Pty Ltd (AFSL 448066). This information is general in nature and does not take into account your personal objectives, financial situation or needs. You should consider whether it is appropriate for you and read the relevant disclosure documents before making any decision.

Python code to retrieve historical time and sales (trading history).

Last updated: April 1, 2025

Historical time and sales for our markets can be retrieved via the REST API Trades endpoint. The entire trading history is available, from the very first trade to the most recent trade.

The following Python 3 code implements a command line API client specifically for retrieving historical time and sales in CSV format, and is provided as an example of how the Trades endpoint can be used:

#!/usr/bin/env python

# Kraken Historical Time and Sales
# Usage: ./krakenhistory symbol start [end]
# Example: ./krakenhistory XXBTZUSD 1559347200 1559433600

import sys
import time
import urllib.request
import json

api_domain = "https://api.kraken.com"
api_path = "/0/public/"
api_method = "Trades"
api_data = ""

if len(sys.argv) < 3:
sys.exit(1)

api_symbol = sys.argv[1].upper()
api_start = str(int(sys.argv[2]) - 1) + "999999999"

if len(sys.argv) > 3:
api_end = sys.argv[3]
else:
api_end = "9999999999"

try:
while True:
api_data = "?pair=%(pair)s&since=%(since)s" % {"pair":api_symbol, "since":api_start}
api_request = urllib.request.Request(api_domain + api_path + api_method + api_data)
try:
api_data = urllib.request.urlopen(api_request).read()
except Exception:
time.sleep(3)
continue
api_data = json.loads(api_data)
if len(api_data["error"]) != 0:
time.sleep(3)
continue
for trade in api_data["result"][api_symbol]:
if int(trade[2]) < int(api_end):
print("%(datetime)d,%(price)s,%(volume)s" % {"datetime":trade[2], "price":trade[0], "volume":trade[1]})
else:
sys.exit(0)
api_start = api_data["result"]["last"]
except KeyboardInterrupt:
None

sys.exit(0)

Need more help?