Rblpapi icon indicating copy to clipboard operation
Rblpapi copied to clipboard

properly catch message when download limit is reach

Open RockScience opened this issue 10 years ago • 6 comments

Following my previous issue, a second one, a bit less important, (although I am bit scared from Dirk's feedback :) Thank you guys for the good work on this project and I am also here to bring a positive contribution from my experience as tester.

When the daily or monthly limit is reached, Rblpapi returns a weird error. "Choice sub-element not found for name 'securityData'."

I have to catch it myself (see below. For clarification purpose, thatis NOT what I think is the best long term solution) , I suggest we catch it inside the code of Rblpapi. In excel the API returns a #N/A limit" error and I guess the C++ API is doing the same?

 # example with bdp but bdh and bds return the same error
 tryCatch({Rblpapi::bdp(securities = "IP Index", fields     = "PX_LAST",  con = con)
     },error=function(e){
      if (e$message=="Choice sub-element not found for name 'securityData'.") {
        stop("BBG limit is reached (daily or monthly)")
      } else {
        stop(e)
      }
    })

RockScience avatar Dec 01 '15 14:12 RockScience

Please look up the help on post formatting and reformat the post.

eddelbuettel avatar Dec 01 '15 14:12 eddelbuettel

Is it better now?

RockScience avatar Dec 01 '15 15:12 RockScience

Much :)

(Minor nag: you used 'r' as the language hint when the language really is C++ ...)

eddelbuettel avatar Dec 01 '15 15:12 eddelbuettel

It so happens that an overzealous colleague also triggered this. Now, I have no plan to repeat this in order to test your suggestion.

And plainly put, two comments. First, you test for

e$message=="Choice sub-element not found for name 'securityData'."

and I recently fixed an error in beqs.cpp where == was used and never worked :) We may need

strcmp(e$message, "Choice sub-element not found for name 'securityData'.") == 0)

Second, the error message from Bloomberg does not say what you pass on. Would it not be more prudent to just pass that message on, rather than guessing? I surmise that we may get this response for more than one error condition.

Lastly, these things tend to work here by fork (or clone), new code, testing leading to pull request. We are all Bloomberg users implying we are all busy professionals. If you want code to move along, make it irresistibly easy for us to integrate it.

eddelbuettel avatar Dec 01 '15 15:12 eddelbuettel

I was right to be scared of your answer ;) My code is in R, not c++? Thanks for your wise suggestions. I agree this tryCatch is not nice, Hence my suggestion to find a cleaner long term solution. We are indeed all busy professionals.No worries I perfectly understand that. I am also usually in favor of reporting bugs even if the solution doesn t come along. It could be extremely easy for someone else to fix it, or if it is not at least you are prepared when the bug actually happens to you!

RockScience avatar Dec 01 '15 15:12 RockScience

This is what I need to do to avoid getting any error from Rblpapi

data = tryCatch({Rblpapi::bdp(securities = securities, 
                                     fields     = fields, 
                                     con        = con, 
                                     options    = NULL, 
                                     overrides  = NULL, 
                                     identity   = NULL)
    },error=function(e) {
      if (e$message=="Choice sub-element not found for name 'securityData'.") {
        stop("This error *usually* happens when BBG limit is reached (daily or monthly)")
      } else {
        stop(e)
      }
    })

Edit 2016-02-25: Simplified as some of the issues have been fixed by @armstrtw

RockScience avatar Dec 02 '15 11:12 RockScience