Description Usage Details API dictionary actions API dictionary exceptions Note References Examples
By default provided to getOption("Rbitcoin.api.dict"). This function returns built-in Rbitcoin data set contains API dictionary for market.api.process function to perform pre-process API call arguments, post-process API call results and catch market level errors. Still there is function market.api.query that do not require any dictionary and can operate on any currency pair. Granularity of api dictionary data is c("market", "base", "quote", "action"). This dictionary can be edited/extended by user for new markets, currency pairs and actions.
Currently supported markets, currency pairs, actions use: api_dict()[!is.na(base), .(market, currency_pair = paste0(base,quote))][,unique(.SD)]
1 | api_dict()
|
Default dictionary post-process function returns list or data.table. The data.table is returned in case of (always) one row response from API (ticker, place_limit_order, etc.). The list is returned in case of (possible) multiple rows response from API (trades, wallet, etc.).
ticker
trades - recent trades, if tid provided then batch of trades data since particular tid.
order_book
wallet - total balance
place_limit_order
open_orders
cancel_order - return 1 row DT on success, if order not found it will suppress error and return 0 row DT, behavior can be changed by getOptions("Rbitcoin.cancel_order.order_not_found") to: NULL (silent-default), "warning", "error".
bitstamp private api calls requires additional param client_id, see bitstamp api docs in references.
Only 3 letters currency codes are supported as input (USD, GBP, BTC, etc.).
btce wallet will not provide total wallet balance if exists open orders, it will raise warning in such case, returned wallet will reflect the non-blocked assets.
btce cancel_order market error with message "bad status" will be suppressed (by default) as it reflects 'order not found' exception. It is unknown if there are more cancel_order errors with such message.
hitbtc cancel_order action requires extended req, see examples below. See repo hitbtc-api issue #3.
hitbtc trades action for recent trades (no tid param) will include content of returned type field, but in case of method for trades since tid param then its field is empty. Open issue in repo hitbtc-com/hitbtc-api issue #4.
hitbtc wallet action will return balance of the hitbtc trading subaccount, see examples below for hitbtc payment (main account) balance query. Also see ?wallet_manager examples for hitbtc main balance in wallet manager.
bitstamp and btce does not support tid (aka since) parameter to trades action. It is not possible to fetch full historical trades from API. See examples for alternative and also a regular API solution (kraken, hitbtc, bitmarket, btcchina).
btcchina cancel_order action optionally requires extended req for market="LTCCNY" etc., the default is "LTCCNY".
Do not use api.dict from untrusted source or read whole it's code to ensure it is safe! The api dictionary was not fully tested, please follow the examples, if you find any bugs please report.
API documentation: https://www.bitstamp.net/api/, https://btc-e.com/api/documentation, https://www.kraken.com/help/api, https://www.bitmarket.pl/docs.php?file=api_private.html, https://github.com/hitbtc-com/hitbtc-api, https://www.btcc.com/apidocs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | ## Not run:
api_dict()[]
# hitbtc cancel order exception
#req = list(oid = "") # as it is for other markets
req = list(oid = "",
symbol = "BTCUSD",
side = "sell") # issue open: https://github.com/hitbtc-com/hitbtc-api/issues/3
cancel_order <- market.api.process(market = 'hitbtc', action = 'cancel_order',
req = req, key = '', secret = '')
# hitbtc payment (main account) balance
r <- market.api.query(market="hitbtc", url="https://api.hitbtc.com/api/1/payment/balance",
key="", secret="")
# historical data FAST: bitcoincharts full archive
browseURL("http://api.bitcoincharts.com/v1/csv/")
# download particular market data dump, extract and load using fread
trades <- fread(".hitbtcEUR.csv")
trades[,`:=`(date = as.POSIXct(V1,origin="1970-01-01", tz="UTC"),
price = V2, amount = V3,
tid = NA_character_, type = NA_character_)
][,c("V1","V2","V3"):=NULL][]
# historical data SLOW: loop using `tid` param - works only on kraken, hitbtc, bitmarket, btcchina!
market="kraken"
currency_pair=c("BTC","LTC")
csv.file = paste(market,paste(currency_pair,collapse=""),"trades.csv",sep="_")
batch_size = 1000 # kraken 1000, hitbtc 1000, bitmarket 500, btcchina 1000
last_tid = 0 # from the beginning
repeat{
trades_batch = tryCatch(
market.api.process(market=market,currency_pair=currency_pair, action="trades",
req=list(tid = last_tid))[["trades"]],
error = function(e){
message(e[["message"]])
invisible(NULL)
}
)
if(is.null(trades_batch)) next # error, skip
if(nrow(trades_batch)==0) break # last batch empty
last_tid <- trades_batch[length(tid),tid]
write.table(trades_batch[,date:=as.integer(date)], csv.file, sep=",", row.names=FALSE,
col.names=!file.exists(csv.file),
append=file.exists(csv.file))
cat(as.character(Sys.time(),"%Y-%m-%d %H-%M-%S"),": inserted ",nrow(trades_batch),
" rows to ",csv.file," file, last inserted tid is ",last_tid,"\n",sep="")
if(nrow(trades_batch) < batch_size) break # last batch
}
trades = fread(csv.file)[,date:=as.POSIXct(date,origin="1970-01-01",tz="UTC")]
print(trades)
# convert trades to xts
trades.xts = trades[,list(date,price,amount)][,xts(.SD[,-1,with=FALSE], order.by=date)]
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.