knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
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.
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)
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.This section provides a detailed walkthrough using KrakenR to access Kraken market data.
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.
# Preview of asset information knitr::kable(head(assets_all))
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.
# Preview of asset information knitr::kable(head(order_book_limited))
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.
# Preview of OHLC data knitr::kable(head(ohlc_data_4h))
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.
# Preview of asset pair information in a simplified two-column table data_frame <- data.frame(Column = names(pairs_all), Example = as.character(pairs_all[1, ])) knitr::kable(data_frame)
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.
# Preview of spread data knitr::kable(head(spread_data))
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.
# Preview of asset pair information in a simplified two-column table data_frame <- data.frame(Column = names(tickers_all), Example = as.character(tickers_all[1, ])) knitr::kable(data_frame)
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")
# Preview of recent trades knitr::kable(head(recent_trades))
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")
# Display system status print(paste("System Status:", status_info))
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")
# Display server times print(paste("UNIX Time:", server_time_unix))
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.