R code:
library(eikonapir)
eikonapir::set_app_id("my-key")
time.start <- Sys.time()
tickers <- c("BRGV5YUSAC=R", "AAHR5YEUAM=R", "ANZ5YUSAR=R", "BBVA5YEUAM=R", "SAN5YEUAM=R", "BAC5YUSAX=R", "BKCH5YUSAC=R", "BNS5YUSAX=MP", "BARC5YEUAM=R", "BNPP5YEUAM=R", "CNDA5YUSAC=R", "C5YUSAX=R", "CBKG5YEUAM=R", "CBA5YUSAR=R", "RABO5YEUAM=R", "CAGR5YEUAM=R", "CSGN5YEUAM=R", "DB5YEUAM=R", "GS5YUSAX=R", "HBCA5YEUAM=R", "INGB5YEUAM=R", "BCIN5YEUAM=R", "JPM5YUSAX=R", "LLTS5YEUAM=R", "MBL5YUSAR=R", "MZFC5YUSAC=R", "MS5YUSAX=R", "MTFC5YUSAC=R", "CNAT5YEUAM=MG", "NDAA5YEUAM=MG", "FINA5YUSAC=MP", "SHIA5YUSAC=R", "SG5YEUAM=R", "STAN5YEUAM=R", "SUMA5YUSAC=R", "SHB5YEUAM=R", "UBSN5YEUAM=R", "UNIC5YEUAM=R", "UOBH5YUSAC=R", "WFC5YUSAX=R", "WBC5YUSAR=R", "WOOR5YUSAC=R", "OCBC5YUSAC=R", "ICBC5YUSAC=MG", "RBS5YEUAM=R")
df <- data.frame(Data = NA, CDS = NA, Ticker = NA)[c(-1),]
for (t in tickers) {
df_aux <- get_timeseries(rics = as.list(t),
fields = list("TIMESTAMP", "CLOSE"),
start_date = format(Sys.Date() - 7, "%Y-%m-%dT%H:%M:%SZ"),
end_date = format(Sys.Date(), "%Y-%m-%dT%H:%M:%SZ"),
interval = "daily")
if (ncol(df_aux) == 3) {
colnames(df_aux) <- c("Data", "CDS", "Ticker")
df <- rbind(df, df_aux)
}
}
time.end <- Sys.time()
(time.taken <- time.end - time.start)
Result: 21.6 minutes
So, my questions:
I) First time I run that script, I didn't mesure, but it took less than 4 minutes, but nowadays it's so slow.. Is there any reason for that long execution?
II) I have to use that if (ncol(df_aux) == 3)
for treat no data or no access data since it return a 2 column dataframe instead of 3 on those cases. Is this the best practice?
III) How to error handling in R? How to get the error message in get_data and get_timeseries?