KrakenR

Introduction

The KrakenR package provides a user-friendly interface to the Kraken cryptocurrency exchange’s REST API. It allows R users to access real-time and historical market data, asset information, and exchange metrics, making it a valuable tool for financial analysts, traders, and researchers interested in the cryptocurrency markets.

This vignette will introduce key functionalities of the package, showcasing how to use the API functions to retrieve market data and more.

Installation

You can install KrakenR directly from GitHub:

# Install the development version from GitHub
devtools::install_github("nathanael-g-durst/KrakenR")
# Load the package
library(KrakenR)

Overview of Available Functions

The package includes several key functions that allow users to fetch various types of data from the Kraken exchange:

  • getAssets() - Retrieve detailed asset information.
  • getOB() - Fetch order book data for a specific trading pair.
  • getOHLC() - Access OHLC (Open, High, Low, Close) data for a trading pair.
  • getPairs() - Retrieve tradable asset pair information.
  • getSpreads() - Fetch recent spread data.
  • getStatus() - Get the current system status of the Kraken exchange.
  • getTickers() - Retrieve detailed ticker information for trading pairs.
  • getTime() - Fetch the current Kraken server time.
  • getTrades() - Retrieve recent trade data for a trading pair.

Example Workflow

This section provides a detailed walkthrough using KrakenR to access Kraken market data.

1. Fetching Asset Information

To retrieve detailed information about all available assets or specific ones:

# Fetch all available assets
assets_all <- getAssets()

# Fetch data for specific assets
assets_specific <- getAssets(c("BTC", "ETH", "ADA"))

The getAssets() function returns a data frame containing asset information, such as the asset class, decimals, and status.

AssetID aclass altname decimals display_decimals status margin_rate Asset collateral_value
0G currency 0G 6 4 enabled 0.02 0G NA
1INCH currency 1INCH 10 5 enabled NULL 1INCH NA
2Z currency 2Z 4 2 enabled 0 2Z NA
A currency A 10 4 enabled 0.02 A NA
AAVE currency AAVE 10 5 enabled 0.02 AAVE 0.8
AB currency AB 3 1 enabled 0 AB NA

2. Retrieving Order Book Data

You can use getOB() to fetch order book data for a specific trading pair:

# Fetch order book data for ADAEUR pair
order_book <- getOB("ADAEUR")

# Fetch order book data with a limit on the number of orders
order_book_limited <- getOB("ADAEUR", count = 3)

The output includes bid and ask orders, sorted by price, and can be used for market analysis.

Bid_Price Bid_Volume Bid_Timestamp Order_Type Ask_Price Ask_Volume Ask_Timestamp
0.214578 934.087 2026-09-30 07:19:36 Bid NA NA NA
0.214579 4059.862 2026-09-30 07:20:59 Bid NA NA NA
0.214711 2051.071 2026-09-30 07:21:00 Bid NA NA NA
NA NA NA Ask 0.214728 2050.923 2026-09-30 07:21:00
NA NA NA Ask 0.214742 2050.809 2026-09-30 07:20:59
NA NA NA Ask 0.214743 2058.825 2026-09-30 07:20:50

3. Fetching OHLC Data

The getOHLC() function allows you to retrieve OHLC (Open, High, Low, Close) data for a given trading pair at various time intervals:

# Fetch 1-minute interval OHLC data for ADAEUR
ohlc_data <- getOHLC("ADAEUR", interval = 1)

# Fetch 4-hour interval data
ohlc_data_4h <- getOHLC("ADAEUR", interval = 240)

This function is useful for technical analysis and charting.

Time Open High Low Close VWAP Volume Count
2026-06-02 04:00:00 0.195688 0.195776 0.191000 0.192191 0.192248 1552039.5 672
2026-06-02 08:00:00 0.192087 0.192556 0.190796 0.191584 0.191511 897100.7 438
2026-06-02 12:00:00 0.191171 0.191877 0.183469 0.184885 0.187154 3329165.7 1541
2026-06-02 16:00:00 0.184783 0.188273 0.182271 0.185232 0.186084 4968679.4 1284
2026-06-02 20:00:00 0.185164 0.187559 0.180223 0.182849 0.183420 1872397.9 850
2026-06-03 00:00:00 0.183091 0.184096 0.178372 0.179349 0.181629 1170606.9 493

4. Getting Asset Pair Information

To retrieve tradable asset pairs and their details:

# Fetch all available asset pairs
pairs_all <- getPairs()

# Fetch information for a specific pair
pair_info <- getPairs(c("ADAEUR", "BTCUSD"))

You can also filter by specific details such as leverage, fees, or margin.

Column Example
PairID 0GEUR
altname 0GEUR
wsname 0G/EUR
aclass_base currency
base 0G
aclass_quote currency
quote ZEUR
lot unit5
cost_decimals 5
pair_decimals 3
lot_decimals 5
lot_multiplier 1
leverage_buy list(leverage_buy = list())
leverage_sell list(leverage_sell = list())
fees list(fees = list())
fees_maker list(fees_maker = list())
fee_volume_currency ZUSD
margin_call 80
margin_stop 40
ordermin 25
costmin 0.45
tick_size 0.001
status online
execution_venue international
Pair 0GEUR
long_position_limit list(NA)
short_position_limit list(NA)

5. Fetching Spread Data

To get recent spread data for a trading pair:

# Fetch spread data for ADAEUR
spread_data <- getSpreads("ADAEUR")

The spread data provides insight into the bid-ask spread over time, which is useful for liquidity analysis.

Time Bid Ask
2026-09-30 07:20:41 0.214658 0.214888
2026-09-30 07:20:41 0.214659 0.214888
2026-09-30 07:20:41 0.214664 0.214888
2026-09-30 07:20:41 0.214665 0.214888
2026-09-30 07:20:42 0.214666 0.214888
2026-09-30 07:20:42 0.214672 0.214888

6. Getting Ticker Information

To fetch real-time ticker information for trading pairs:

# Fetch ticker information for all pairs
tickers_all <- getTickers()

# Fetch ticker information for specific pairs
tickers_specific <- getTickers(c("ADAEUR", "BTCUSD"))

This function provides real-time price, volume, and trading information.

Column Example
PairID 0GEUR
Pair 0GEUR
Ask_Price 0.303
Ask_WholeLotVolume 1319
Ask_LotVolume 1319
Bid_Price 0.302
Bid_WholeLotVolume 989
Bid_LotVolume 989
LastTrade_Price 0.297
LastTrade_LotVolume 297.50964
Volume_Today 78191.06191
Volume_24h 246788.83851
VWAP_Today 0.299382
VWAP_24h 0.293936
Trades_Today 120
Trades_24h 460
Low_Today 0.276
Low_24h 0.253
High_Today 0.32
High_24h 0.32
Open_Price 0.288

7. Fetching Recent Trade Data

To retrieve recent trade data for a trading pair:

# Fetch recent trades for ADAEUR
recent_trades <- getTrades("ADAEUR")

# Fetch trades since a specific timestamp
recent_trades_since <- getTrades("ADAEUR", since = "2024-10-01 12:00:00")
Price Volume Time Order_Type Execution_Type Miscellaneous Trade_ID
0.214692 20.0000000 2026-09-30 07:20:56 buy limit 14617051
0.214974 2048.2486000 2026-09-30 07:20:33 buy limit 14617050
0.214874 1162.5000000 2026-09-30 07:20:33 buy limit 14617049
0.214920 0.0000001 2026-09-30 07:20:05 sell limit 14617048
0.214946 2048.4402112 2026-09-30 07:20:05 sell limit 14617046
0.214920 2048.6864287 2026-09-30 07:20:05 sell limit 14617047

8. Retrieving System Status

To check the operational status of the Kraken exchange:

# Fetch both system status and timestamp
status_info <- getStatus()

# Fetch only system status
system_status <- getStatus("status")
#> [1] "System Status: online"               "System Status: 2026-09-30T07:21:04Z"

9. Retrieving Server Time

You can check the current server time in UNIX or RFC formats:

# Fetch UNIX time
server_time_unix <- getTime("unix")

# Fetch RFC 1123 time
server_time_rfc <- getTime("rfc")
#> [1] "UNIX Time: 2026-09-30 07:21:05"