Learn R Programming

binancer

An R client to the Public Rest API for Binance.

API docs: https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md

Quick intro to using binancer by getting the most recent ~USD price of the cryptocurrencies supported on Binance:

library(binancer)
binance_coins_prices()

Getting data on a specific symbol pair, e.g. the most recent Bitcoin/USDT changes:

(klines <- binance_klines('BTCUSDT', interval = '1m'))

Visualize this data, e.g. on a simple line chart:

library(ggplot2)
ggplot(klines, aes(close_time, close)) + geom_line()

Poor man's candle chart with some ggplot2 tweaks:

library(scales)
ggplot(klines, aes(open_time)) +
  geom_linerange(aes(ymin = open, ymax = close, color = close < open), size = 2) +
  geom_errorbar(aes(ymin = low, ymax = high), size = 0.25) +
  theme_bw() + theme('legend.position' = 'none') + xlab('') +
  ggtitle(paste('Last Updated:', Sys.time())) +
  scale_y_continuous(labels = dollar) +
  scale_color_manual(values = c('#1a9850', '#d73027')) # RdYlGn

Extend this to multiple pairs in the past 24 hours using 15 mins intervals:

library(data.table)
klines <- rbindlist(lapply(
  c('ETHBTC', 'ARKBTC', 'NEOBTC', 'IOTABTC'),
  binance_klines,
  interval = '15m',
  limit = 4*24))
ggplot(klines, aes(open_time)) +
  geom_linerange(aes(ymin = open, ymax = close, color = close < open), size = 2) +
  geom_errorbar(aes(ymin = low, ymax = high), size = 0.25) +
  theme_bw() + theme('legend.position' = 'none') + xlab('') +
  ggtitle(paste('Last Updated:', Sys.time())) +
  scale_color_manual(values = c('#1a9850', '#d73027')) +
  facet_wrap(~symbol, scales = 'free', nrow = 2)

Copy Link

Version

Install

install.packages('binancer')

Monthly Downloads

423

Version

1.2.0

License

AGPL

Maintainer

Gergely Daróczi

Last Published

November 29th, 2021

Functions in binancer (1.2.0)

binance_cancel_order

Cancel order on the Binance account
binance_account

Get current general Binance account information, without balances
binance_coins_prices

Get all currently valid coin names from Binance along with the USDT prices
binance_avg_price

Get current average price for a symbol
binance_key

Look up Binance API key stored in the environment
binance_check_credentials

Check if Binance credentials were set previously
binance_open_orders

Fetch open orders from the Binance account
binance_ping

Test connectivity to the Rest API
binance_credentials

Sets the API key and secret to interact with the Binance API
binance_ticker_all_books

Get latest Binance bids and asks on all symbol pairs
binance_ticks

Get tick data from Binance
binance_klines

Get kline/candlestick data from Binance
binance_depth

Get orderbook depth data from Binance
binance_time

Get the current server time from Binance
binance_ticker_all_prices

Get latest Binance conversion rates and USD prices on all symbol pairs
timestamp

Return current UNIX timestamp in millisecond
binance_all_orders

Fetch all orders from the Binance account
binance_exchange_info

Get exchangeInfo from Binance
binance_mytrades

Get trades for a specific symbol on the Binance account
binance_new_order

Open new order on the Binance account
binance_query

Request the Binance API
binance_balances

Get current Binance balances in a nice table
binance_filters

Get current filters for a symbol
binance_query_order

Query order on the Binance account
binance_symbols

Get all currently valid symbol names from Binance
binance_ticker_24hr

24 hour rolling window price change statistics
binance_secret

Look up Binance API secret stored in the environment
binance_ticker_book

Get last bids and asks for a symbol or all symbols
binance_sign

Sign the query string for Binance
query

Make an API request with retries
binance_trades

Get last trades from Binance
binance_ticker_price

Get last price for a symbol or all symbols
binance_coins

Get all currently valid coin names from Binance