You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
KrakenR provides a comprehensive R interface to access data from the Kraken cryptocurrency exchange's REST API. It allows users to retrieve various market data, such as asset information, system status, trading pairs, and price data.
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 GitHubdevtools::install_github("nathanael-g-durst/KrakenR")
# Load the packagelibrary(KrakenR)
Overview of Available Functions
The package includes several key functions that allow users to fetch various types of data from the Kraken exchange:
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 assetsassets_all <- getAssets()# Fetch data for specific assetsassets_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 informationknitr::kable(head(assets_all))
2. Retrieving Order Book Data
You can usegetOB() to fetch order book data for a specific trading pair:
# Fetch order book data for ADAEUR pairorder_book <- getOB("ADAEUR")# Fetch order book data with a limit on the number of ordersorder_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 informationknitr::kable(head(order_book_limited))
3. Fetching OHLC Data
ThegetOHLC() function allows you to retrieve OHLC (Open, High, Low, Close) data for a given trading pair at various time intervals:
This function is useful for technical analysis and charting.
# Preview of OHLC dataknitr::kable(head(ohlc_data_4h))
4. Getting Asset Pair Information
To retrieve tradable asset pairs and their details:
# Fetch all available asset pairspairs_all <- getPairs()# Fetch information for a specific pairpair_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 tabledata_frame <- data.frame(Column = names(pairs_all), Example = as.character(pairs_all[1, ]))knitr::kable(data_frame)
5. Fetching Spread Data
To get recent spread data for a trading pair:
# Fetch spread data for ADAEURspread_data <- getSpreads("ADAEUR")
The spread data provides insight into the bid-ask spread over time, which is useful for liquidity analysis.
# Preview of spread dataknitr::kable(head(spread_data))
6. Getting Ticker Information
To fetch real-time ticker information for trading pairs:
# Fetch ticker information for all pairstickers_all <- getTickers()# Fetch ticker information for specific pairstickers_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 tabledata_frame <- data.frame(Column = names(tickers_all), Example = as.character(tickers_all[1, ]))knitr::kable(data_frame)
7. Fetching Recent Trade Data
To retrieve recent trade data for a trading pair:
# Fetch recent trades for ADAEURrecent_trades <- getTrades("ADAEUR")# Fetch trades since a specific timestamprecent_trades_since <- getTrades("ADAEUR", since = "2024-10-01 12:00:00")
# Preview of recent tradesknitr::kable(head(recent_trades))
8. Retrieving System Status
To check the operational status of the Kraken exchange:
# Fetch both system status and timestampstatus_info <- getStatus()# Fetch only system statussystem_status <- getStatus("status")
# Display system statusprint(paste("System Status:", status_info))
9. Retrieving Server Time
You can check the current server time in UNIX or RFC formats:
# Display server timesprint(paste("UNIX Time:", server_time_unix))
About
KrakenR provides a comprehensive R interface to access data from the Kraken cryptocurrency exchange's REST API. It allows users to retrieve various market data, such as asset information, system status, trading pairs, and price data.