binance_klines

Get klines data for a trading pair with Binance API.

  • Github function here.

Example: Spot (spot)

Get 1-day OHLC data for BTCUSDT

Show the code
library(binancer)
# import depth data from binance 
klines <- binance_klines(pair = "BTCUSDT", api = "spot", interval = "1d", from = Sys.Date()-5)

df_klines <- head(klines, n = 5)

Get 1-hour OHLC data for BTCUSDT

Show the code
library(binancer)
# import depth data from binance 
klines <- binance_klines(pair = "BTCUSDT", api = "spot", interval = "1h")

df_klines <- head(klines, n = 5)

Get 1-minutes OHLC data for BTCUSDT

Show the code
library(binancer)
# import depth data from binance 
klines <- binance_klines(pair = "BTCUSDT", api = "spot", interval = "1m", 
                         from = Sys.Date() - 1, to = Sys.time())

df_klines <- head(klines, n = 5)

Get 1-second OHLC data for BTCUSDT

Show the code
library(binancer)
# import depth data from binance 
klines <- binance_klines(pair = "BTCUSDT", api = "spot", interval = "1s", 
                         from = Sys.time() - 1000, to = Sys.time())

df_klines <- head(klines[-1,], n = 5)

Examples: Futures USD-m (fapi)

Get 1-day OHLC data for BTCUSDT

Show the code
library(binancer)
# import depth data from binance 
klines <- binance_klines(pair = "BTCUSDT", api = "fapi", 
                         interval = "1d", from = Sys.Date()-5)

df_klines <- head(klines, n = 5)

Get 1-hour OHLC data for BTCUSDT

Show the code
library(binancer)
# import depth data from binance 
klines <- binance_klines(pair = "BTCUSDT", api = "fapi", interval = "1h")

df_klines <- head(klines, n = 5)

Get 1-minutes OHLC data for BTCUSDT

Show the code
library(binancer)
# import depth data from binance 
klines <- binance_klines(pair = "BTCUSDT", api = "fapi", 
                         interval = "1m", from = Sys.Date() - 1, to = Sys.time(), quiet = TRUE)

df_klines <- head(klines, n = 5)

Examples: Futures COIN-m (dapi)

Get 1-day OHLC data for BTCUSDT

Show the code
library(binancer)
# import depth data from binance 
klines <- binance_klines(pair = "BTCUSD_PERP", api = "dapi", 
                         interval = "1d", from = Sys.Date()-5)

df_klines <- head(klines, n = 5)

Get 1-hour OHLC data for BTCUSD_PERP

Show the code
library(binancer)
# import depth data from binance 
klines <- binance_klines(pair = "BTCUSD_PERP", api = "dapi", interval = "1h")

df_klines <- head(klines, n = 5)

Get 1-minutes OHLC data for BTCUSD_PERP

Show the code
library(binancer)
# import depth data from binance 
klines <- binance_klines(pair = "BTCUSD_PERP", api = "dapi", 
                         interval = "1m", from = Sys.Date()-1, to = Sys.time())

df_klines <- head(klines, n = 5)

Examples: Options (eapi)

BTC-240628-30000-P is a Put contract with strike price 30000 and expiry date on 28-06-2024.

Get 1-day OHLC data for BTC-240628-30000-P

Show the code
library(binancer)
# import depth data from binance 
klines <- binance_klines(pair = "BTC-240628-30000-P", api = "eapi", 
                         interval = "1d", from = Sys.Date()-5)

df_klines <- head(klines, n = 5)

Get 1-hour OHLC data for BTC-240628-30000-P

Show the code
library(binancer)
# import depth data from binance 
klines <- binance_klines(pair = "BTC-240628-30000-P", api = "eapi", 
                         interval = "1h")

df_klines <- head(klines, n = 5)

Get 1-minutes OHLC data for BTC-240628-30000-P

Show the code
# import depth data from binance 
klines <- binance_klines(pair = "BTC-240628-30000-P", api = "eapi", 
                         interval = "1m", from = Sys.Date() - 1, to = Sys.time())

df_klines <- head(klines, n = 5)
Back to top

Citation

BibTeX citation:
@online{sartini2024,
  author = {Sartini, Beniamino},
  date = {2024-06-18},
  url = {https://cryptoverser.org/binancer-docs/binance_klines.html},
  langid = {en}
}
For attribution, please cite this work as:
Sartini, Beniamino. 2024. June 18, 2024. https://cryptoverser.org/binancer-docs/binance_klines.html.