market.api.process: Process market API

Description Usage Arguments Details Value Note See Also Examples

View source: R/market.R

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 response to unified structure across markets.

Usage

1
2
3
4
market.api.process(market, currency_pair, action, req = list(), ...,
  skip_post_process = FALSE, api.dict = getOption("Rbitcoin.api.dict",
  stop("no api.dict in options! options('Rbitcoin.api.dict')")),
  verbose = getOption("Rbitcoin.verbose", 0))

Arguments

market

character, example: 'kraken'.

currency_pair

character vector of length 2, e.g. c(base = 'BTC', quote = 'EUR'), names are not mandatory but order does matter. It will also handle the action param provided in case of market.api.process("kraken","wallet").

action

character, defined process/method to get organized data.

  • 'ticker' returns data.table ticker information.

  • 'wallet' returns list wallet information like currency, amount.

  • 'order_book' returns list with API call level attributes and sub elements [['asks']] and [['bids']] as data.table objects with order book including already calculated cumulative amount, price and value.

  • 'open_orders' returns list open orders information like oid, type, price, amount.

  • 'place_limit_order' returns data.table with fields: oid, type, price, amount.

  • 'cancel_order' returns data.table with fields like oid.

  • 'trades' returns list with API call level attributes and sub element [['trades']] as data.table (ASC order) with fields: date, price, amount, tid, type.

req

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

skip_post_process

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

api.dict

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

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.

...

objects to be passed to market.api.query and farther to particular market query (read query.dict).

  • auth params: key, secret

  • auth param on bitstamp: client_id

  • any other args in case of own custom market function

Details

By default it will perform antiddos check and wait if required, it can be turned off but in such case you should expect to be banned quite easily. Read ?antiddos.

Value

Unless skip_post_process==TRUE the returned value depends on the action param but does not depend on market anymore. It returns a list or data.table. It will also result truncation of most (not common across the markets) attributes returned. If you need the full set of data returned by markets API you might use skip_post_process=TRUE. All actions will return API call response but also metadata about API call itself, in a common structure across different markets. Follow Rbitcoin introduction vignette or examples.

Note

The api dictionary was not fully tested, if you find any bugs please report. Use only api dictionaries from trusted source or review them before using!

See Also

market.api.query, api.dict, antiddos, query.dict

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
## Not run: 
# get ticker from market
market.api.process(market = 'kraken', currency_pair = c('BTC', 'EUR'), action='ticker')

# get ticker from few markets and combine
op <- options("Rbitcoin.antiddos.verbose" = 1) # will print antiddos waiting time
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'),
  market.api.process(market = 'btce', currency_pair = c('LTC', 'BTC'), action='ticker'),
  market.api.process(market = 'kraken', currency_pair = c('BTC','EUR'), action='ticker'),
  market.api.process(market = 'kraken', currency_pair = c('LTC','EUR'), action='ticker'),
  market.api.process(market = 'kraken', currency_pair = c('BTC','LTC'), action='ticker')
))
options(op)
print(ticker_all)

# get wallet from market
market.api.process(market = 'kraken', action = 'wallet', key = '', secret = '')

# get wallet from all markets and combine
wallet_all <- rbindlist(list(
  market.api.process(market = 'bitstamp', action = 'wallet',
                     client_id = '', key = '', secret = '')[['wallet']],
  market.api.process(market = 'btce', action = 'wallet',
                     method = '', key = '', secret = '')[['wallet']],
  market.api.process(market = 'kraken', action = 'wallet',
                     key = '', secret = '')[['wallet']]
))
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', 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', action = 'cancel_order',
                   req = list(oid = 'oid_from_open_orders'),
                   key = '', secret = '')

# get trades, since arg allowed: `req = list(tid = "123456")`
market.api.process(market = 'kraken', currency_pair = c('BTC', 'EUR'), action = 'trades')

## End(Not run)

jangorecki/Rbitcoin documentation built on May 18, 2019, 12:24 p.m.