Rblp / Rblpapi

R package interfacing the Bloomberg API from https://www.bloomberglabs.com/api/
Other
166 stars 75 forks source link

Error in bdh_Impl: Attempt to access out of range index '0' on array element 'fieldData' which has 0 value(s). #340

Closed egghead168 closed 3 years ago

egghead168 commented 3 years ago

Hi,

the following code keeps getting an error. Is it because my blpapi version is not compatible? I believe I'm using blpapi 3.7.1.1.

Thanks.

library(Rblpapi) Rblpapi version 0.3.11 using Blpapi headers 3.8.18.1 and run-time 3.8.18.1. Please respect the Bloomberg licensing agreement and terms of service. con <- blpConnect() a <- bdh("IBM Equity", c("PX LAST", "VOLUME"), start.date = Sys.Date()-30) Error in bdh_Impl(con, securities, fields, start.date, end.date, options, : Attempt to access out of range index '0' on array element 'fieldData' which has 0 value(s).

mtkerbeR commented 3 years ago

I think the reason are typos in parameter securities (where an exchange ticker like "US" is missing) and a missing underscore "_" in parameter fields ("PX LAST" should be "PX_LAST"):

library(Rblpapi)
blpConnect()

# not working
bdh("IBM Equity", c("PX LAST", "VOLUME"), start.date = Sys.Date()-30)

# working - adding "US" in securities and "_" in field "PX_LAST"
bdh("IBM US Equity", c("PX_LAST", "VOLUME"), start.date = Sys.Date()-30)
egghead168 commented 3 years ago

ah, changing "PX LAST" to "PX_LAST" worked. Thanks a lot. If you use Bloomberg API in excel, both will work fine. So I didn't realize they were treated differently here.