Binance API
Binance API is a method that allows you to connect to the Binance servers using several programming languages. With it, you can automate your trading and make HTTP requests to send and receive data. Here we access Binance API using R with httr2 package. We will be sending requests to Binance API and extracting the real-time price of the required cryptocurrency in JSON format.
Get Crypto Price Using R And Binance API
We will be using the library httr2 to make requests and store the data. httr2 handles everything, including JSON formats. You can install the library as follows.
# install httr2
install.packages('httr2', dependencies = TRUE)
Performing Binance API requests:
# 1) perform GET-request
# for latest BTCUSDT ticker price
response <- httr2::req_perform(
req = httr2::request(
'https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT'
)
)
# 2) binance returns
# a json object which can
# be extacted directly
response <- httr2::resp_body_json(
resp = response
)
# 3) extract price
# and symbol
price <- as.numeric(
response$price
)
symbol <- response$symbol
# 4) print the results
# with appropriate labelling
print(
paste(
symbol, 'price is', price
)
)
Output:
[1] "BTCUSDT price is 43913.58"
Get Real-Time Crypto Currencies Price Using R and Binance API
In this article, we are going to see how to get the real-time price of cryptocurrencies using Binance API in R Programming Language.
Contact Us