Learn R Programming

cryptowatchR (version 0.2.0)

get_orderbook: Get order book of cryptocurrencies

Description

Get the order book of cryptocurrencies using the REST API of cryptowat.ch. The route is orderbook and returns two arrays, bids and asks. See https://docs.cryptowat.ch/rest-api/markets/order-book for further information.

Usage

get_orderbook(pair, depth = NULL, span = NULL, limit = NULL,
              exchange = "kraken", api_key = NULL, allowance = FALSE)

Arguments

pair

A string containing a pair symbol, e.g. btcusd (required argument). Run get_pairs() to find other available pairs.

depth

A number: Only return orders cumulating up to this size (optional).

span

A number: Only return orders within this percentage of the midpoint (optional). Example: 0.5 (meaning 0.5 percent).

limit

An integer limiting the number of orders on each side of the book (optional).

exchange

A character string containing the exchange. Default is kraken. Run get_exchanges() to find other available exchanges.

api_key

A character string containing the API key. See https://docs.cryptowat.ch/rest-api/rate-limit to learn how to create an account and how to generate an API key.

allowance

A logical (default is FALSE). If TRUE the function returns a list which includes allowance information, i.e. cost of the request, remaining credits and your account name.

Value

A list containing an order book of a given pair of currencies. It contain two data.frames for bid and ask prices with columns Price and Amount. The function also returns the sequence number seqNum. If allowance is TRUE, get_orderbook() returns a list which additionally includes allowance information.

References

See https://docs.cryptowat.ch/rest-api for further information.

See Also

get_markets, get_orderbook_liquidity, get_exchanges, get_pairs

Examples

Run this code
# NOT RUN {
# Entire order book of Bitcoin in USD
orderbook <- get_orderbook("btcusd")
# Order book of Bitcoin in USD: only the best bid and best ask, i.e. the spread
orderbook.limit <- get_orderbook("btcusd", limit = 1)
# Order book of Bitcoin in USD for orders within 0.5% of the top of the book
orderbook.span <- get_orderbook("btcusd", span = 0.5)
# Order book of Bitcoin in Euro for orders adding up to 100 BTC on each side
orderbook.depth <- get_orderbook("btceur", depth = 100)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab