## load library
library(cryptoQuotes)By default all data is returned with
Sys.timezone() and, if not specified otherwise, all
dates passed into the get-functions are
Sys.timezone() too.
Different time zones
OHLC (Local)
If from and to are passed as valid
date-type characters, sys.time()
or as.POSIXct() without specifying the TZ the
returned xts::index() is ‘as is’,
OHLC (UTC)
If from and to are passed as
as.POSIXct() while specifying the TZ the
returned xts::index() is internally converted,
## Get hourly
## BTC between
## 20.00 and 22.00 from
## yesterday
BTC_utc <- get_quote(
ticker = "BTCUSD",
source = "kraken",
interval = "1h",
futures = FALSE,
from = as.POSIXct(paste(Sys.Date()-1, "20:00:00"), tz = "UTC"),
to = as.POSIXct(paste(Sys.Date()-1, "22:00:00"), tz = "UTC")
)Changing the time zones
All time zones can be converted using the
xts::tzone()-function. Below is an example of converting
the BTC to UTC,
## 1) Change time
## zone to UTC
##
## Store BTC_utc in
## a new variable to avoid
## replacing it. Not necessary in the
## real world - its just for
## demonstrations
BTC_tzone <- BTC_utc
xts::tzone(BTC_tzone) <- "UTC"| Original Index | Converted Index |
|---|---|
| 2024-05-17 20:00:00 | 2024-05-17 20:00:00 |
| 2024-05-17 21:00:00 | 2024-05-17 21:00:00 |
| 2024-05-17 22:00:00 | 2024-05-17 22:00:00 |
The converted time zones now match the original
argument-input in BTC_utc.
