geckor has several functions that can retrieve historical market data for cryptocurrencies. All of these functions have the “coin_history” prefix in their names. In all of the examples described below, we will be collecting historical data for Bitcoin.

To obtain coin-specific market data for a given historical date, you can use the coin_history_snapshot() function:

coin_history_snapshot(
  coin_id = "bitcoin",
  date = as.Date("2021-01-01"),
  vs_currencies = c("usd", "eur", "gbp")
)

The coin_history_range() function can be used to query a range of historical dates specified by the from and to arguments, which expect POSIXct timestamps. The granularity of the returned data depends on the requested range. Hourly data will be retrieved for periods of up to 90 days, and daily data for periods longer than 90 days:

# Range of less than 1 day:
coin_history_range(
  coin_id = "bitcoin",
  vs_currency = "usd",
  from = as.POSIXct("2020-01-01 10:00:10"),
  to = as.POSIXct("2020-01-01 20:45:10")
)

# Range of >90 days:
coin_history_range(
  coin_id = "bitcoin",
  vs_currency = "usd",
  from = as.POSIXct("2021-01-01 00:00:00"),
  to = as.POSIXct("2021-05-01 00:00:00")
)

To retrieve historical data from the last n days only, use the coin_history():

coin_history(
  coin_id = "bitcoin",
  vs_currency = "usd",
  days = 7
)

In addition to numeric values, the days argument also accepts a character value "max", which results in retrieving the entire existing history of market data for a coin (please note that querying the entire history can take some time):

coin_history(
  coin_id = "bitcoin",
  vs_currency = "usd",
  days = "max"
)

Notice the different data granularity in the last two examples. Generally, if days = 1 the data will be presented for approximately every 3-8 minutes. If days is between 2 and 90 (inclusive), an hourly time step will be used. Daily data are used for days above 90. You can use the interval argument to control this granularity (by default, interval = NULL), but at the moment the only value it accepts is "daily":

# Within-day data, with `interval = "daily"`:
coin_history(
  coin_id = "bitcoin",
  vs_currency = "usd",
  days = 1,
  interval = "daily"
)

# Less than 90 days, with `interval = "daily"`:
coin_history(
  coin_id = "bitcoin",
  vs_currency = "usd",
  days = 10,
  interval = "daily"
)

# More than 90 days, with `interval = "daily"`:
coin_history(
  coin_id = "bitcoin",
  vs_currency = "usd",
  days = 100,
  interval = "daily"
)

The open-high-low-close (OHLC) data characterise within-date and between-date price movements of a financial asset. In geckor, you can retrieve this type of data using the coin_history_ohlc() function, which has the same arguments as coin_history() except for not having the interval argument. Granularity of the retrieved data (i.e. candle’s body) depends on the value of days as follows:

  • 1 day: 30 minutes

  • 7 - 30 days: 4 hours

  • 31 and above: 4 days

The only values currently accepted by the days argument are 1, 7, 14, 30, 90, 180, 365 and "max". Here are some examples:

# 30-minutes granularity:
coin_history_ohlc(
  coin_id = "bitcoin",
  vs_currency = "usd",
  days = 1
)

# 4-hours granularity:
coin_history_ohlc(
  coin_id = "bitcoin",
  vs_currency = "usd",
  days = 7
)

# 4-days granularity:
coin_history_ohlc(
  coin_id = "bitcoin",
  vs_currency = "usd",
  days = 90
)

# 4-days granularity:
coin_history_ohlc(
  coin_id = "bitcoin",
  vs_currency = "usd",
  days = "max"
)

As of v0.3.0 of the package, all of the coin_history_* functions can retrieve data for up to 5 coins in one call. To do that, you need to pass a vector of coin IDs to the coin_id argument. In the following example, we collect market data from the last 2 days for Bitcoin, Cardano and Polkadot:

coin_history(
  coin_id = c("bitcoin", "cardano", "polkadot"),
  vs_currency = "usd",
  days = 2,
  interval = "daily"
)