market.api.process: Process market API

Description Usage Arguments Details Value Note See Also Examples

Description

Unified processing of API call according to API dictionary api.dict. Limited to markets and currency processing defined in api.dict, in case of currency pairs and methods not availble in dictionary use market.api.query directly. This function perform pre processing of request and post processing of API call results to unified structure across markets. It will result truncation of most (not common across the markets) attributes returned. If you need the full set of data returned by market's API you should use market.api.query.

Usage

1
2
3
4
5
market.api.process(market, currency_pair, action, req = list(), ...,
  verbose = getOption("Rbitcoin.verbose", 0),
  on.market.error = expression(stop(e[["message"]], call. = FALSE)),
  on.error = expression(stop(e[["message"]], call. = FALSE)),
  api.dict = NULL, raw.query.res = FALSE)

Arguments

market

character, example: 'kraken'.

currency_pair

character vector of length 2, ex. c(base = 'BTC', quote = 'EUR'). Order does matter.

action

character, defined process to get organized data.

req

list with action details (price, amount, tid, oid, etc.) unified across the markets specific per action, see examples.

...

objects to be passed to market.api.query

  • auth params: key, secret, client_id (last one used on bitstamp),

verbose

integer. Rbitcoin processing messages, print to console if verbose > 0, each subfunction reduce verbose by 1. If missing then getOption("Rbitcoin.verbose",0) is used, by default 0.

on.market.error

expression to be evaluated on market level error. Rules specified in api.dict.

on.error

expression to be evaluated on R level error related to market.api.query. For details read market.api.query.

api.dict

data.table user custom API dictionary definition, if not provided function will use default Rbitcoin api.dict.

raw.query.res

logical skip post-processing are return results only after fromJSON processing. Useful in case of change results structure from market API. It can always be manually post-processed as a workaround till the Rbitcoin update.

Details

To do not spam market's API, use Sys.sleep(10) between API calls.

Value

Returned value depends on the action param. All actions will return market, currency pair (except wallet and open_orders which returns all currencies), R timestamp, market timestamp and below data (in case if market not provide particular data, it will result NA value):

Note

The api dictionary was not fully tested, please follow the examples, if you find any bugs please report. Use only api dictionary api.dict from trusted source, in case if you use other api.dict it is advised to review pre-process, post-process and catch_market_error functions for markets and currency pairs you are going to use. Market level error handling might not fully work as not all markets returns API call status information.

See Also

market.api.query

Examples

 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
## Not run: 
# get ticker from market
market.api.process(market = 'kraken', currency_pair = c('BTC', 'EUR'), action='ticker')
# get ticker from all markets and combine
ticker_all <- rbindlist(list(
  market.api.process(market = 'bitstamp', currency_pair = c('BTC', 'USD'), action='ticker')
  ,market.api.process(market = 'btce', currency_pair = c('LTC', 'USD'), action='ticker')
  ,{Sys.sleep(10);
    market.api.process(market = 'btce', currency_pair = c('LTC', 'BTC'), action='ticker')}
  ,{Sys.sleep(10);
    market.api.process(market = 'btce', currency_pair = c('NMC', 'BTC'), action='ticker')}
  ,market.api.process(market = 'kraken', currency_pair = c('BTC','EUR'), action='ticker')
  ,{Sys.sleep(10);
    market.api.process(market = 'kraken', currency_pair = c('LTC','EUR'), action='ticker')}
  ,{Sys.sleep(10);
    market.api.process(market = 'kraken', currency_pair = c('BTC','LTC'), action='ticker')}
))
print(ticker_all)

# get wallet from market
market.api.process(market = 'kraken', currency_pair = c('BTC', 'EUR'), action = 'wallet',
                   key = '', secret = '')
# get wallet from all markets and combine
wallet_all <- rbindlist(list(
  market.api.process(market = 'bitstamp', currency_pair = c('BTC', 'USD'), action = 'wallet',
                     client_id = '', key = '', secret = ''),
  market.api.process(market = 'btce', currency_pair = c('LTC', 'USD'), action = 'wallet',
                     method = '', key = '', secret = ''),
  market.api.process(market = 'kraken', currency_pair = c('BTC', 'EUR'), action = 'wallet',
                     key = '', secret = '')
))
print(wallet_all)

# get order book from market
market.api.process(market = 'kraken', currency_pair = c('BTC', 'EUR'), action = 'order_book')

# get open orders from market
market.api.process(market = 'kraken', currency_pair = c('BTC', 'EUR'), action = 'open_orders',
                   key = '', secret = '')

# place limit order
market.api.process(market = 'kraken', currency_pair = c('BTC', 'EUR'), action = 'place_limit_order',
                   req = list(type = 'sell', amount = 1, price = 8000), # sell 1 btc for 8000 eur
                   key = '', secret = '')

# cancel order
market.api.process(market = 'kraken', currency_pair = c('BTC', 'EUR'), action = 'cancel_order,
                   req = list(oid = 'oid_from_open_orders'),
                   key = '', secret = '')
# get trades
market.api.process(market = 'kraken', currency_pair = c('BTC', 'EUR'), action = 'trades')

## End(Not run)

Rbitcoin documentation built on May 2, 2019, 3:41 p.m.