Class that encapsulates the core API methods to communicate with the Binance API.
Methods
Method new()
Arguments
profile
(string
) the name of the configuration to read the API configurations.
Print method
Print high level information about the object.
Arguments
...
additional arguments to print
Setup API Key and Secret
Providing the object with the Binance API key and Secret to perform authenticated requests.
Method sign_in()
Usage
Binance$sign_in(
api_key = Sys.getenv("BINANCE_API_KEY"),
api_secret = Sys.getenv("BINANCE_API_SECRET")
)
Arguments
api_key
(string
) the Binance API key.
Will be taken from the environment variable BINANCE_API_KEY
if not provided.
api_secret
(string
) the Binance API secret.
Will be taken from the environment variable BINANCE_API_SECRET
if not provided.
Test Connectivity
Test connectivity to the Rest API by logging the connection status.
Method test_connectivity()
Usage
Binance$test_connectivity()
Returns
a httr2
response object.
Check Server Time
Test connectivity to the Rest API and get the current server time.
Method check_server_time()
Usage
Binance$check_server_time()
Returns
a POSIXct
object with the server time.
Exchange Information
Current exchange trading rules and symbol information
Method get_exchange_info()
Usage
Binance$get_exchange_info()
Returns
a tibble
with the exchange information.
Order Book
Get the order book for a given symbol.
Method order_book()
Usage
Binance$order_book(symbol, limit = 100)
Arguments
symbol
(string
) the trading symbol.
limit
(integer
) the number of orders to return. Default 100; max 5000.
If limit > 5000, then the response will truncate to 5000.
Returns
a list
with the last update id, bids, and asks.
Recent Trades List
Get recent trades for a given symbol.
Method recent_trades_list()
Usage
Binance$recent_trades_list(symbol, limit = 500)
Arguments
symbol
(string
) the trading symbol.
limit
(integer
) the number of trades to return. Default 500; max 1000.
Old Trade Lookup
Get older market trades for a given symbol.
Method old_trade_lookup()
Usage
Binance$old_trade_lookup(symbol, limit = 500, from_id = NULL)
Arguments
symbol
(string
) the trading symbol.
limit
(integer
) the number of trades to return. Default 500; max 1000.
from_id
(integer
) trade id to fetch from. Default gets most recent trades.
Kline/Candlestick Data
Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
Method kline()
Usage
Binance$kline(
symbol,
interval,
start_time = NULL,
end_time = NULL,
time_zone = "0",
limit = 500
)
Arguments
symbol
(string
) the trading symbol.
interval
(string
) the interval for the kline/candlestick bars.
Valid values: 1s
,1m
,3m
,5m
,15m
,30m
,1h
,2h
,4h
,6h
,8h
,12h
,1d
,3d
,1w
, 1M
Where: s-> seconds; m -> minutes; h -> hours; d -> days; w -> weeks; M -> months
start_time
(numeric
) the start time for the klines in epoch milliseconds.
end_time
(numeric
) the end time for the klines in epoch milliseconds.
time_zone
(string
) the time zone to use for the start and end time. Default is "0" (UTC).
limit
(integer
) the number of klines to return. Default 500; max 1000.
Returns
a tibble
with the kline data.
24hr Ticker Price Change Statistics
24 hour rolling window price change statistics. Careful when accessing this with no symbol.
Method ticker_stats_24hr()
Usage
Binance$ticker_stats_24hr(symbols)
Arguments
symbols
(character
) the trading symbols of interest.
Returns
a tibble
with the price change statistics.
Symbol Price Ticker
Latest price for a symbol or symbols.
Method price_ticker()
Usage
Binance$price_ticker(symbols)
Arguments
symbols
(character
) the trading symbols of interest.
Returns
a tibble
with the price ticker.
Method clone()
The objects of this class are cloneable with this method.
Usage
Binance$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.