Loading...
You don't need an API key to read market data. Kraken's /0/public/OHLC endpoint is free and unmetered.
GET https://api.kraken.com/0/public/OHLC?pair=XXBTZUSD&interval=60pair = Kraken's internal pair code. Use AssetPairs endpoint to look them up.interval = minutes per bar. 1, 5, 15, 30, 60, 240, 1440, 10080, 21600.Response:
json{ "error": [], "result": { "XXBTZUSD": [[1713840000, "65000.0", "65300.0", "64800.0", "65150.0", "65050.0", "123.4", 456], ...], "last": 1713844800 } }
Each bar is [time, open, high, low, close, vwap, volume, count] — all as strings.
pythonimport urllib.request, json url = "https://api.kraken.com/0/public/OHLC?pair=XXBTZUSD&interval=60" data = json.loads(urllib.request.urlopen(url).read()) bars = next(iter(data["result"].values())) # grab the pair array, skip "last" closes = [float(b[4]) for b in bars if isinstance(b, list)] print(f"latest close: ${closes[-1]:.2f}")
The sandbox has preloaded historical data via load_dataset("BTC_DAILY_2024"). That's the same shape — so we'll practice on that.
Load the BTC dataset, compute the simple moving average of the last 20 closes, and print it.