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:
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.
AssetID | aclass | altname | decimals | display_decimals | status | Asset | collateral_value |
---|---|---|---|---|---|---|---|
1INCH | currency | 1INCH | 10 | 5 | enabled | 1INCH | NA |
AAVE | currency | AAVE | 10 | 5 | enabled | AAVE | 0.8 |
ACA | currency | ACA | 10 | 5 | enabled | ACA | NA |
ACH | currency | ACH | 10 | 5 | enabled | ACH | NA |
ADA | currency | ADA | 8 | 6 | enabled | ADA | 0.9 |
ADA.S | currency | ADA.S | 8 | 6 | enabled | ADA.S | NA |
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.698086 | 270.000 | 2024-11-18 23:42:54 | Bid | NA | NA | NA |
0.698090 | 20278.406 | 2024-11-18 23:43:06 | Bid | NA | NA | NA |
0.698091 | 86.779 | 2024-11-18 23:43:06 | Bid | NA | NA | NA |
NA | NA | NA | Ask | 0.698487 | 531.810 | 2024-11-18 23:43:06 |
NA | NA | NA | Ask | 0.698488 | 33778.084 | 2024-11-18 23:43:06 |
NA | NA | NA | Ask | 0.698490 | 360.181 | 2024-11-18 23:43:05 |
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 |
---|---|---|---|---|---|---|---|
2024-07-22 00:00:00 | 0.410000 | 0.412912 | 0.402658 | 0.402658 | 0.407833 | 89500.19 | 96 |
2024-07-22 04:00:00 | 0.403218 | 0.403802 | 0.394673 | 0.398754 | 0.398090 | 145027.95 | 365 |
2024-07-22 08:00:00 | 0.398749 | 0.402853 | 0.396017 | 0.402433 | 0.400360 | 180837.85 | 245 |
2024-07-22 12:00:00 | 0.401985 | 0.403048 | 0.394219 | 0.395215 | 0.398420 | 181719.59 | 289 |
2024-07-22 16:00:00 | 0.394415 | 0.397723 | 0.393181 | 0.397581 | 0.394209 | 226646.02 | 307 |
2024-07-22 20:00:00 | 0.398169 | 0.398169 | 0.389424 | 0.392028 | 0.395443 | 153254.60 | 179 |
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 | 1INCHEUR |
altname | 1INCHEUR |
wsname | 1INCH/EUR |
aclass_base | currency |
base | 1INCH |
aclass_quote | currency |
quote | ZEUR |
lot | unit |
cost_decimals | 5 |
pair_decimals | 3 |
lot_decimals | 8 |
lot_multiplier | 1 |
leverage_buy | list(leverage_buy = list()) |
leverage_sell | list(leverage_sell = list()) |
fees | list(fees = c(0, 10000, 50000, 1e+05, 250000, 5e+05, 1e+06, 2500000, 5e+06, 1e+07, 0.4, 0.35, 0.24, 0.22, 0.2, 0.18, 0.16, 0.14, 0.12, 0.1)) |
fees_maker | list(fees_maker = c(0, 10000, 50000, 1e+05, 250000, 5e+05, 1e+06, 2500000, 5e+06, 1e+07, 0.25, 0.2, 0.14, 0.12, 0.1, 0.08, 0.06, 0.04, 0.02, 0)) |
fee_volume_currency | ZUSD |
margin_call | 80 |
margin_stop | 40 |
ordermin | 11 |
costmin | 0.45 |
tick_size | 0.001 |
status | online |
Pair | 1INCHEUR |
long_position_limit | list(NA) |
short_position_limit | list(NA) |
To get recent spread data for a trading pair:
The spread data provides insight into the bid-ask spread over time, which is useful for liquidity analysis.
Time | Bid | Ask |
---|---|---|
2024-11-18 23:42:45 | 0.698112 | 0.698549 |
2024-11-18 23:42:45 | 0.698113 | 0.698549 |
2024-11-18 23:42:45 | 0.698113 | 0.698548 |
2024-11-18 23:42:46 | 0.698144 | 0.698548 |
2024-11-18 23:42:46 | 0.698145 | 0.698548 |
2024-11-18 23:42:46 | 0.698145 | 0.698547 |
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 | 1INCHEUR |
Pair | 1INCHEUR |
Ask_Price | 0.314 |
Ask_WholeLotVolume | 43728 |
Ask_LotVolume | 43728 |
Bid_Price | 0.313 |
Bid_WholeLotVolume | 9627 |
Bid_LotVolume | 9627 |
LastTrade_Price | 0.315 |
LastTrade_LotVolume | 84.68257688 |
Volume_Today | 42295.00571728 |
Volume_24h | 42295.00571728 |
VWAP_Today | 0.30272 |
VWAP_24h | 0.30272 |
Trades_Today | 84 |
Trades_24h | 84 |
Low_Today | 0.283 |
Low_24h | 0.283 |
High_Today | 0.316 |
High_24h | 0.316 |
Open_Price | 0.283 |
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.698087 | 531.76464 | 2024-11-18 23:42:53 | buy | limit | 11449426 | |
0.698814 | 31.26741 | 2024-11-18 23:42:40 | buy | market | 11449425 | |
0.699622 | 137.75267 | 2024-11-18 23:42:29 | buy | limit | 11449424 | |
0.699721 | 32.55742 | 2024-11-18 23:42:02 | buy | market | 11449423 | |
0.699455 | 3005.49840 | 2024-11-18 23:42:02 | sell | market | 11449422 | |
0.699160 | 78.74157 | 2024-11-18 23:41:42 | buy | limit | 11449421 |