Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • Eikon Data APIs /

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

avatar image
Question by ty · Aug 19, 2020 at 02:47 PM · eikoneikon-data-apipythonworkspaceworkspace-data-apirefinitiv-dataplatform-eikonrerror-handling

Response time too long, Error Handling in R

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?


People who like this

0 Show 0
Comment
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

3 Replies

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by Jirapongse · Aug 20, 2020 at 04:34 AM

@ty

The efficient way is getting raw data and then create a data frame from the raw data.

You can send one request of all items if it doesn't exceed 3000 datapoints as mentioned in the EIKON DATA API USAGE AND LIMITS GUIDELINE.

The code looks like:


get_formatted_data_frame  <- function(data)
{
  input_data_frame = data$timeseriesData
  data_frames <- list()
  for (i in 1:nrow(input_data_frame))
  { current_row = input_data_frame[i,]    
    if (is.na(current_row$errorCode)==FALSE) {
        next
    }   
    current_fields  = current_row$fields[[1]]$name
    ric_column = rep( current_row$ric,nrow(input_data_frame[i,]))
    data_frame  <- as.data.frame(current_row$dataPoints[[1]],stringsAsFactors = FALSE)   
    data_frame <- cbind(data_frame, Security=ric_column)
    names(data_frame) <- current_fields
    data_frames[[i]] = data_frame
  }
  return (do.call("rbind", data_frames))
}

raw <- get_timeseries(rics = list("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"),
                           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",
                           raw_output = TRUE)
data = jsonlite::fromJSON(raw)
get_formatted_data_frame(data)
Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

avatar image
Answer by ty · Sep 08, 2020 at 05:47 PM

Sorry for the delay, it does solve my problem with the "raw_output = TRUE" option! Thanks a lot!

Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

avatar image
Answer by krunallathiya21.kl · Feb 06, 2021 at 08:50 AM

When you are writing big programs, sometimes something goes wrong with your R code. What do you do if the program stops unexpectedly? What tools do you have to address the problem? This is where the tryCatch() function will help you. Debugging is the art and science of fixing unexpected problems in your code.


You can use the tryCatch() exception handling method to resolve most of your issues.


Thanks,

Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Watch this question

Add to watch list
Add to your watch list to receive emailed updates for this question. Too many emails? Change your settings >
10 People are following this question.

Related Questions

Historical GDP in USD

I'm trying to use an API connection (using R) to extract some data that we need. However, it seems that my autentication settings are not correct or I'm using a wrong code. Can you please help me?

Eikon API to retrieve timeseries data through R package

how to use eikonapi fetching Bond data in R?

How can I set up API for R?

  • Copyright
  • Cookie Policy
  • Privacy Statement
  • Terms of Use
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Alpha
  • App Studio
  • Block Chain
  • Bot Platform
  • Connected Risk APIs
  • DSS
  • Data Fusion
  • Data Model Discovery
  • Datastream
  • Eikon COM
  • Eikon Data APIs
  • Electronic Trading
    • Generic FIX
    • Local Bank Node API
    • Trading API
  • Elektron
    • EMA
    • ETA
    • WebSocket API
  • FX Venues
    • FX Trading – RFQ Maker
  • Intelligent Tagging
  • Legal One
  • Messenger Bot
  • Messenger Side by Side
  • ONESOURCE
    • Indirect Tax
  • Open Calais
  • Open PermID
    • Entity Search
  • Org ID
  • PAM
    • PAM - Logging
  • ProView
  • ProView Internal
  • Product Insight
  • Project Tracking
  • RDMS
  • Refinitiv Data Platform
    • Refinitiv Data Platform Libraries
  • Rose's Space
  • Screening
    • Qual-ID API
    • Screening Deployed
    • Screening Online
    • World-Check One
    • World-Check One Zero Footprint
  • Side by Side Integration API
  • TR Knowledge Graph
  • TREP APIs
    • CAT
    • DACS Station
    • Open DACS
    • RFA
    • UPA
  • TREP Infrastructure
  • TRKD
  • TRTH
  • Thomson One Smart
  • Transactions
    • REDI API
  • Velocity Analytics
  • Wealth Management Web Services
  • Workspace SDK
    • Element Framework
    • Grid
  • World-Check Data File
  • Yield Book Analytics
  • 中文论坛
  • Explore
  • Tags
  • Questions
  • Badges