This package provides a user-friendly R interface to the Poloniex (Cryptocurrency Trading) REST API.
The package has been submitted to CRAN and will most likely be released in the near future (after approval). After the release date, the package can be installed in the usual manner:
install.packages("PoloniexR")
Before the release date, the package can be installed from github by using the devtools
utility:
# install.packages("devtools") # if devtools currently not installed devtools::install_github("VermeirJellen/PoloniexR")
Following the installation, the library can be loaded: library(PoloniexR)
.
The package exposes 2 S4 classes to the users:
PoloniexPublicAPI
: Consists of wrapper methods on top of the Poloniex Public REST API.PoloniexTradingAPI
: Consists of wrapper methods on top of the Poloniex Trading REST API.Methods provided by the PoloniexPublicAPI
:
ReturnTicker
Return24hVolume
ReturnOrderBook
ReturnTradeHistory
ReturnChartData
ReturnCurrencies
ReturnLoanOrders
Methods provided by the PoloniexTradingAPI
:
ReturnBalances
ReturnCompleteBalances
Use?<function.name>
to read full I/O specs and function documentation. cfr ?ReturnTicker
.
Examples are provided in the sections below
Run ?ReturnTicker
for additional function documentation.
library(PoloniexR) poloniex.public <- PoloniexPublicAPI() ticker.info <- ReturnTicker(poloniex.public) head(ticker.info)
Run ?Return24hVolume
for additional function documentation.
poloniex.public <- PoloniexPublicAPI() volume.info <- Return24hVolume(poloniex.public) head(volume.info$volume.pairs) volume.info$volume.totals
Run ?ReturnOrderBook
for additional function documentation.
pair <- "BTC_NXT" depth <- 10 order.book <- ReturnOrderBook(poloniex.public, pair = pair, depth = depth) head(order.book$bid) head(order.book$ask) order.book$frozen order.book$seq pair <- "all" depth <- 10 order.book <- ReturnOrderBook(poloniex.public, pair = pair, depth = depth) order.book$BTC_ETH$bid order.book$BTC_ETH$ask order.book$BTC_ETH$frozen order.book$BTC_ETH$seq
Run ?ReturnTradeHistory
for additional function documentation.
Sys.setenv(tz="UTC") pair <- "BTC_ETH" from <- as.POSIXct("2017-07-01 00:00:00 UTC") to <- as.POSIXct("2017-07-04 00:00:00 UTC") trades.data <- ReturnTradeHistory(theObject = poloniex.public, pair = pair, from = from, to = to) tail(trades.data)
Run ?ReturnChartData
for additional function documentation.
Sys.setenv(tz="UTC") pair <- "BTC_ETH" from <- as.POSIXct("2015-01-01 00:00:00 UTC") to <- as.POSIXct("2018-04-09 00:00:00 UTC") period <- "4H" chart.data <- ReturnChartData(theObject = poloniex.public, pair = pair, from = from, to = to, period = period) tail(chart.data) # install.packages("quantmod") library(quantmod) chart.plot <- chart_Series(chart.data[, "close"], type = "line", name = "BTC_ETH", subset = "201705/201708") chart.plot <- add_MACD() chart.plot <- add_BBands() chart.plot <- add_RSI() chart.plot
Run ?ReturnCurrencies
for function additional function documentation.
currencies <- ReturnCurrencies(poloniex.public) head(currencies)
Run ?ReturnLoanOrders
for additional function documentation.
currency <- "BTC" loan.orders <- ReturnLoanOrders(poloniex.public, currency = currency) head(loan.orders$offers) head(loan.orders$demands)
Note: Changing these settings is only useful if Poloniex makes changes to the base URL and/or command strings in the future. If nothing changes, object construction can remain default.
library(PoloniexR) poloniex.public <- PoloniexPublicAPI() # Default constructor GetPoloniexPublicURL(poloniex.public) poloniex.public <- PoloniexPublicAPI(base.url = "https://not_working/public?") poloniex.public <- SetPoloniexPublicURL(poloniex.public, base.url = "https://poloniex.com/public?") GetPoloniexPublicURL(poloniex.public) GetPoloniexPublicCommands(poloniex.public) commands.new <- list(returnTicker = "returnTicker.new", return24hVolume = "return24hVolume.new") # missing commands are kept default poloniex.public <- SetPoloniexPublicCommands(poloniex.public, commands = commands.new) GetPoloniexPublicCommands(poloniex.public)
Trading should be enabled in your Poloniex settings and you should have access to your account key / secret in order to construct the PoloniexTradingAPI
object. Internally, all calls to the trading API are sent via HTTP POST. The POST data itself is signed with your key's secret according to the HMAC-SHA512 method.
Wrapper on top of ProcessTradingRequest
to fetch account balance info. Run ?ReturnBalances
for additional info.
key = your.key secret = your.secret poloniex.trading <- PoloniexTradingAPI(key = key, secret = secret) balances <- ReturnBalances(poloniex.trading) head(balances)
Wrapper on top of ProcessTradingRequests
to fetch complete (margin, lending, ..) account balance info. Run ?ReturnCompleteBalances
for additional info.
balances <- ReturnCompleteBalances(poloniex.trading) head(balances) balances <- ReturnCompleteBalances(poloniex.trading, all.balances=TRUE) head(balances)
This function allows the users to call any of the trading functions that are accessible through the Poloniex Trading API. The ProcessTradingRequest
method takes a command string as input argument in combination with a list of additional input arguments that correspond to the particular command in question.
Some examples:
########################## # returnDepositAddresses # ########################## ?ProcessTradingRequest deposit.addresses <- ProcessTradingRequest(poloniex.trading, command = poloniex.trading@commands$returnDepositAddresses) ######################### # generateNewAddress #### ######################### new.address <- ProcessTradingRequest(poloniex.trading, command = poloniex.trading@commands$generateNewAddress, args = list(currency = "BTC")) ############################## # returnDepositsWithdrawals ## ############################## account.activity <- ProcessTradingRequest(poloniex.trading, command = poloniex.trading@commands$returnDepositsWithdrawals, args = list(start = as.numeric(as.POSIXct("2017-01-01 00:00:00 UTC"))), end = as.numeric(as.POSIXct("2018-01-01 00:00:00 UTC"))) ############################## ### returnOpenOrders ######### ############################## open.orders <- ProcessTradingRequest(poloniex.trading, command = poloniex.trading@commands$returnOpenOrders, args = list(currencyPair = "BTC_ETH")) open.orders.all <- ProcessTradingRequest(poloniex.trading, command = poloniex.trading@commands$returnOpenOrders, args = list(currencyPair = "all")) ############################## ### Return Trade History ##### ############################## trade.history <- ProcessTradingRequest(poloniex.trading, command = poloniex.trading@commands$returnTradeHistory, args = list(currencyPair = "BTC_ETH", start = as.numeric(as.POSIXct("2017-01-01 00:00:00 UTC"))), end = as.numeric(as.POSIXct("2018-01-01 00:00:00 UTC"))) # no range specified: limit to one day trade.history.all <- ProcessTradingRequest(poloniex.trading, command = poloniex.trading@commands$returnTradeHistory, args = list(currencyPair = "all")) ############################## ### ReturnOrderTrades ######## ############################## order.trades <- ProcessTradingRequest(poloniex.trading, command = poloniex.trading@commands$returnOrderTrades, args = list(orderNumber = 1)) ############################## ######### Buy ################ ############################## buy.order <- ProcessTradingRequest(poloniex.trading, command = poloniex.trading@commands$buy, args = list(currencyPair = "BTC_ETH", rate = 0.01, amount = 1, immediateOrCancel = 1)) # fillOrKill, postOnly ############################## ######### Sell ############### ############################## sell.order <- ProcessTradingRequest(poloniex.trading, command = poloniex.trading@commands$sell, args = list(currencyPair = "BTC_ETH", rate = 0.01, amount = 1)) ############################## ######### cancelOrder ######## ############################## cancel.order <- ProcessTradingRequest(poloniex.trading, command = poloniex.trading@commands$cancelOrder, args = list(orderNumber = 1)) ############################## ######### moveOrder ########## ############################## move.order <- ProcessTradingRequest(poloniex.trading, command = poloniex.trading@commands$moveOrder, args = list(orderNumber = 1, rate = 0.1, amount = 1, immediateOrCancel = 1)) # postOnly
Other Trade functionality (View Poloniex API documentation):
poloniex.trading@commands$withdraw
poloniex.trading@commands$returnFeeInfo
poloniex.trading@commands$returnAvailableAccountBalances
poloniex.trading@commands$returnTradeableBalances
poloniex.trading@commands$transferBalance
poloniex.trading@commands$returnMarginAccountSummary
poloniex.trading@commands$marginBuy
poloniex.trading@commands$marginSell
poloniex.trading@getMarginPosition
poloniex.trading@closeMarginPosition
poloniex.trading@commands$createLoanOffer
poloniex.trading@commands$cancelLoanOffer
poloniex.trading@commands$returnOpenLoanOffers
poloniex.trading@commands$returnActiveLoans
poloniex.trading@commands$returnLendingHistory
poloniex.trading@commands$toggleAutoRenew
Same remark as before: Modification of the object fields are only required if and when Poloniex modifies the trading API base URL and/or the command strings. Default constructor can be used for now.
########################################################### #################### GETTERs / SETTERS #################### ########################################################### ################## # Get Trading URL# ################## GetPoloniexTradingURL(poloniex.trading) ################## # Set Trading URL# ################## ?SetPoloniexTradingURL poloniex.trading <- PoloniexTradingAPI(trading.base.url = "https://not_working/tradingApi?", key = your.key, secret = your.secret) poloniex.trading <- SetPoloniexTradingURL(poloniex.trading, trading.base.url = "https://poloniex.com/tradingApi?") GetPoloniexTradingURL(poloniex.trading) ####################### # Get Trading commands# ####################### ?GetPoloniexTradingCommands GetPoloniexTradingCommands(poloniex.trading) ####################### # Set Trading Commands# ####################### ?SetPoloniexTradingCommands commands.new <- list(returnTradeHistory = "returnTradeHistory.new", withdraw = "withdraw.new") poloniex.trading <- SetPoloniexTradingCommands(poloniex.trading, commands = commands.new) GetPoloniexTradingCommands(poloniex.trading) commands.new <- list(returnTicker = "returnTicker.new", return24hVolume = "return24hVolume.new") poloniex.trading <- SetPoloniexTradingCommands(poloniex.trading, commands = commands.new) GetPoloniexPublicCommands(poloniex.public)
If you find this software useful and/or you would like to see additional extensions, feel free to donate some crypto:
Or preferably, donate some of my favorite coins :)
Copyright 2017 Essential Data Science Consulting ltd. (EssentialQuant.com / jellenvermeir@essentialquant.com). This software is copyrighted under the MIT license: View added LICENSE file.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.