Learn R Programming

cryptoQuotes (version 1.3.0)

get_lsratio: Get the long to short ratio of a cryptocurrency pair

Description

[Stable]

Get the long-short ratio for any available_tickers() from the available_exchanges()

Usage

## long-short ratio
get_lsratio(
   ticker,
   interval = '1d',
   source   = 'binance',
   from     = NULL,
   to       = NULL,
   top      = FALSE
)

Value

An xts-object containing,

  • long (numeric) - the share of longs

  • short (numeric) - the share of shorts

  • ls_ratio (numeric) - the ratio of longs to shorts

Arguments

ticker

A character vector of length 1. See available_tickers() for available tickers.

interval

A character vector of length 1. See available_intervals() for available intervals.

source

A character-vector of length 1. See available_exchanges() for details.

from

An optional vector of length 1. Can be Sys.Date()-class, Sys.time()-class or as.character() in %Y-%m-%d format.

to

An optional vector of length 1. Can be Sys.Date()-class, Sys.time()-class or as.character() in %Y-%m-%d format.

top

A logical vector. FALSE by default. If TRUE it returns the top traders Long-Short ratios.

Author

Jonas Cuzulan Hirani

Details

On time-zones and dates

Values passed to from or to must be coercible by as.Date(), or as.POSIXct(), with a format of either "%Y-%m-%d" or "%Y-%m-%d %H:%M:%S". By default all dates are passed and returned with Sys.timezone().

On returns

If only from is provided 200 pips are returned up to Sys.time(). If only to is provided 200 pips up to the specified date is returned.

See Also

Other get-function: get_fgindex(), get_fundingrate(), get_openinterest(), get_quote()

Examples

Run this code
if (FALSE) {
  # Example on loading
  # long-short ratio
  # for the last days
  # on the 15 minute candle
  # wrapped in try to avoid
  # failure on Github

  # 1) long-short ratio
  # on BTCUSDT pair
  ls_ratio <- cryptoQuotes::get_lsratio(
    ticker = 'BTCUSDT',
    interval = '15m',
    from = Sys.Date() - 1,
    to   = Sys.Date()
  )

  # 2) BTCSDT in same period
  # as the long-short ratio;
  BTC <- cryptoQuotes::get_quote(
    ticker = 'BTCUSDT',
    futures = TRUE,
    interval = '15m',
    from = Sys.Date() - 1,
    to   = Sys.Date()
  )

  # 3) plot BTCUSDT-pair
  # with long-short ratio
  cryptoQuotes::chart(
    ticker = BTC,
    main   = cryptoQuotes::kline(),
    sub    = list(
      cryptoQuotes::lsr(ratio = ls_ratio),
      cryptoQuotes::volume()
    ),
    indicator = list(
      cryptoQuotes::bollinger_bands()
    )
  )
}



# end of scrtipt;

Run the code above in your browser using DataLab