Kraken Historical Downloader (dccd.histo_dl.kraken)

Objects to download historical data from Kraken exchange.

class FromKraken(path, crypto, span, fiat='USD', form='xlsx', tz='local')[source]

Bases: ImportDataCryptoCurrencies

Class to import crypto-currencies data from the Kraken exchange.

Parameters:
pathstr

Root directory for data files.

cryptostr

Crypto-currency symbol, e.g. 'BTC'.

spanint or str

Candle interval in seconds (minimum 60) or a label such as 'hourly' or '1h'.

fiatstr, optional

Quote currency. Default is 'USD'. The resulting Kraken pair uses the X/Z prefix scheme (e.g. 'USD''XXBTZUSD'); use format_pair to inspect the resolved symbol.

formstr, optional

Legacy parameter — ignored. Storage is always Parquet via DataStore.

tzstr, optional

Timezone for date parsing: 'local' (default), 'UTC', or any IANA timezone name.

Attributes:
pairstr

Pair symbol, crypto + fiat.

start, endint

Timestamp to starting and ending download data.

spanint

Number of seconds between observations.

full_pathstr

Directory managed by DataStore{path}/kraken/ohlc/{pair}/{span}/.

Methods

import_data([start, end])

Download data from Kraken since a specific time until now.

save([form, by_period])

Save df to disk via DataStore.

get_data([format])

Return the downloaded data.

import_trades([start, end])

Fetch individual trades for a time window.

save_trades([form, by_period])

Save trades_df via DataStore.

import_orderbook([depth])

Fetch the current order book snapshot at a given depth.

save_orderbook([form])

Save orderbook_df via DataStore.

See also

FromBinance, FromCoinbase, FromBybit, FromOKX

Notes

See Kraken API documentation [1] for more details on parameters.

References

get_data(format='polars')

Return the downloaded data.

Parameters:
format{‘polars’, ‘pandas’}, optional

Output format. Default is ‘polars’.

Returns:
pl.DataFrame

Current data in the requested format.

import_data(start='last', end=None)[source]

Download data from Kraken since a specific time until now.

Parameters:
startint or str

Timestamp of the first observation as a Unix timestamp (int) or a date string 'yyyy-mm-dd hh:mm:ss'.

endint, str or None

Ignored. The Kraken OHLC API does not support a custom end date and always returns data up to the current time. Passing a non-None value raises a UserWarning.

Returns:
selfFromKraken

Data sorted and cleaned in a data frame, accessible via get_data.

import_orderbook(depth=50)

Fetch the current order book snapshot at a given depth.

Downloads the bid/ask ladder from the exchange REST API, validates each level, and stores the result in orderbook_df. Use save_orderbook to persist to disk.

Parameters:
depthint, optional

Number of price levels to fetch per side (bids + asks), default 50. Maximum varies by exchange.

Returns:
ImportDataCryptoCurrencies

Returns self for method chaining.

Notes

Order book REST endpoints return a current snapshot only. Historical order book data is not available via public APIs.

import_trades(start=0, end='now')

Fetch individual trades for a time window.

Downloads executed trades from the exchange REST API, validates each record, and stores the result in trades_df. Use save_trades to persist to disk.

Parameters:
startint or str, optional

Start of the time window. Accepts a Unix timestamp (int), a date string 'yyyy-mm-dd hh:mm:ss', or 0 (default, meaning “as far back as the API allows”).

endint or str, optional

End of the time window. 'now' (default) resolves to the current UTC time. Accepts a Unix timestamp or date string.

Returns:
ImportDataCryptoCurrencies

Returns self for method chaining.

Notes

Exchanges vary in how much history they expose:

  • Binance and Kraken provide full paginated history.

  • OKX exposes several months of history via cursor pagination.

  • Bybit returns the ~1 000 most recent trades regardless of start/end.

  • Coinbase returns up to 100 recent trades (cursor-based, no deep history).

save(form='parquet', by_period='Y')

Save df to disk via DataStore.

Data is always written as Parquet, grouped annually. The form and by_period parameters are accepted for backward compatibility but ignored — storage format and period granularity are managed by DataStore.

Parameters:
formstr, optional

Ignored. Kept for backward-compatibility.

by_periodstr, optional

Ignored. Kept for backward-compatibility.

save_orderbook(form='parquet')

Save orderbook_df via DataStore.

The snapshot is timestamped with the current UTC time and written into the daily orderbook file. The form parameter is accepted for backward compatibility but ignored.

Parameters:
formstr, optional

Ignored. Kept for backward-compatibility.

Returns:
ImportDataCryptoCurrencies

Returns self to allow method chaining.

save_trades(form='parquet', by_period='D')

Save trades_df via DataStore.

Trades are grouped by calendar day and written as Parquet. The form and by_period parameters are accepted for backward compatibility but ignored.

Parameters:
formstr, optional

Ignored. Kept for backward-compatibility.

by_periodstr, optional

Ignored. Kept for backward-compatibility.

Returns:
ImportDataCryptoCurrencies

Returns self to allow method chaining.

FromKraken downloads OHLCV candles, trade history, and order book snapshots from the Kraken public REST API. No authentication is required.

Exchange specifics

Pair format

Kraken uses a prefix scheme: most pairs become 'X' + crypto + 'Z' + fiat (e.g. 'BTC' + 'USD''XXBTZUSD'). Stablecoins and a few majors skip the prefix (e.g. 'BCHUSD'). format_pair resolves this automatically.

OHLCV endpoint limitation

GET /0/public/OHLC does not accept an end timestamp — it always returns data up to now. The end parameter of import_data() is ignored with a UserWarning.

Candles per request

720 (Kraken returns up to 720 bars per call).

Trade history

Full historical depth via GET /0/public/Trades, paginated by Unix nanosecond timestamp.

Order book depth

Snapshot at 1–500 price levels per side.

Daemon backfill strategy

Because the OHLCV endpoint lacks pagination, the daemon uses KrakenBackfill which reconstructs OHLC bars from the full trade history and resamples them.

Authentication

Not required for public data.

Quick example

from dccd.histo_dl import FromKraken

# Pair format is handled automatically (BTC + USD → XXBTZUSD)
obj = FromKraken('/data/crypto/', 'BTC', span=3600, fiat='USD')

# 'end' is ignored for OHLCV — Kraken always fetches up to now
obj.import_data(start='2024-01-01 00:00:00', end='2024-12-31 00:00:00')
obj.save(form='parquet')

# Full trade history with pagination
obj.import_trades(start='2024-01-01 00:00:00', end='2024-06-30 00:00:00')
obj.save_trades(form='parquet')