properly catch message when download limit is reach
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)
}
})
Please look up the help on post formatting and reformat the post.
Is it better now?
Much :)
(Minor nag: you used 'r' as the language hint when the language really is C++ ...)
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.
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!
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