Rblp / Rblpapi

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

getBars doesn't work for equities #366

Closed MislavSag closed 2 years ago

MislavSag commented 2 years ago

I am trying to get historical (bar) data using getBars function. The function works for SPX:

getBars("SPX Index")

but it doesn't work for equities:

getBars("GOOG Equity")

The error:

REQUEST FAILED: responseError = { source = "bbdbl2" code = 15 category = "BAD_SEC" message = "Unknown/Invalid security [nid:15842] " subcategory = "INVALID_SECURITY" }
[1] times     open      high      low       close     numEvents volume    value    
<0 rows> (or 0-length row.names)

I have tried some other equity symbols but got the same error.

johnlaing commented 2 years ago

I have no issues with your call on GOOG. You'll need to give us some more information/attempt to isolate the issue:

MislavSag commented 2 years ago

1) If I set verbose to TRUE:

getBars("GOOG Equity", startTime = as.POSIXct("2022-07-04 15:00:00"), verbose = TRUE)

I get:

Sending Request: IntradayBarRequest = { security = "GOOG Equity" eventType = TRADE interval = 60 startDateTime = 2022-07-04T13:00:00 endDateTime = 2022-07-06T04:15:51 }
Processing Response
REQUEST FAILED: responseError = { source = "bbdbl7" code = 15 category = "BAD_SEC" message = "Unknown/Invalid security [nid:758] " subcategory = "INVALID_SECURITY" }
[1] times     open      high      low       close     numEvents volume    value    
<0 rows> (or 0-length row.names)

2) I have tried "GOOG Equity" with bhm function and it seems it doesn't work either. For example this works:

spx <- bdh(securities = "SPX Index", 
           fields = "PX_LAST", 
           start.date = as.Date("2000-03-01"))

but this:

bdh(securities = "GOOG Equity", 
    fields = "PX_LAST", 
    start.date = as.Date("2000-03-01"),
    verbose = TRUE)

returns:

HistoricalDataResponse = {
    securityData = {
        security = "GOOG Equity"
        eidData[] = {
        }
        sequenceNumber = 0
        securityError = {
            source = "52892:rsfhdsvc1"
            code = 15
            category = "BAD_SEC"
            message = "Unknown/Invalid securityInvalid Security [nid:52892]"
            subcategory = "INVALID_SECURITY"
        }
        fieldExceptions[] = {
        }
        fieldData[] = {
        }
    }
}
[1] date    PX_LAST
<0 rows> (or 0-length row.names)

I have just begun with Bloomberg Desktop API. Maybe market data for is not enabled. I will check with bloomberg support.

3) I have tried to add currency too, but it doesn't work either:

instruments <- c("SPX Index", "GOOG Equity", "EURUSD Crncy")
lapply(instruments, getBars, startTime = as.POSIXct("2022-07-04 15:00:00"), verbose = TRUE)

returns:

Sending Request: IntradayBarRequest = { security = "SPX Index" eventType = TRADE interval = 60 startDateTime = 2022-07-04T13:00:00 endDateTime = 2022-07-06T04:22:09 }
Processing Response
Response contains 7 bars
Datetime        Open        High        Low     Close       NumEvents   Volume      V
7/5/2022 13:30      3792.610        3792.610        3742.060        3756.190        3600        0       0.000
7/5/2022 14:30      3755.890        3774.550        3743.640        3750.240        3600        0       0.000
7/5/2022 15:30      3749.830        3783.500        3747.270        3779.420        3600        0       0.000
7/5/2022 16:30      3779.560        3786.360        3765.410        3782.770        3600        0       0.000
7/5/2022 17:30      3782.820        3803.440        3780.390        3802.360        3600        0       0.000
7/5/2022 18:30      3802.550        3826.640        3802.550        3824.450        3600        0       0.000
7/5/2022 19:30      3824.340        3832.190        3819.500        3831.390        2700        0       0.000
Sending Request: IntradayBarRequest = { security = "GOOG Equity" eventType = TRADE interval = 60 startDateTime = 2022-07-04T13:00:00 endDateTime = 2022-07-06T04:22:10 }
Processing Response
REQUEST FAILED: responseError = { source = "bbdbl8" code = 15 category = "BAD_SEC" message = "Unknown/Invalid security [nid:203] " subcategory = "INVALID_SECURITY" }
Sending Request: IntradayBarRequest = { security = "EURUSD Crncy" eventType = TRADE interval = 60 startDateTime = 2022-07-04T13:00:00 endDateTime = 2022-07-06T04:22:10 }
Processing Response
REQUEST FAILED: responseError = { source = "bbdbl4" code = 15 category = "BAD_SEC" message = "Unknown/Invalid security [nid:203] " subcategory = "INVALID_SECURITY" }
[[1]]
                times    open    high     low   close numEvents volume value
1 2022-07-05 13:30:00 3792.61 3792.61 3742.06 3756.19      3600      0     0
2 2022-07-05 14:30:00 3755.89 3774.55 3743.64 3750.24      3600      0     0
3 2022-07-05 15:30:00 3749.83 3783.50 3747.27 3779.42      3600      0     0
4 2022-07-05 16:30:00 3779.56 3786.36 3765.41 3782.77      3600      0     0
5 2022-07-05 17:30:00 3782.82 3803.44 3780.39 3802.36      3600      0     0
6 2022-07-05 18:30:00 3802.55 3826.64 3802.55 3824.45      3600      0     0
7 2022-07-05 19:30:00 3824.34 3832.19 3819.50 3831.39      2700      0     0

[[2]]
[1] times     open      high      low       close     numEvents volume    value    
<0 rows> (or 0-length row.names)

[[3]]
[1] times     open      high      low       close     numEvents volume    value    
<0 rows> (or 0-length row.names)

I will try to contact Bloomberg support. and send feedback here.

MislavSag commented 2 years ago

Important update:

Seems the function works if I use cusip number. For AAPL:

# this works
getBars("/cusip/037833100", startTime = as.POSIXct("2022-07-04 15:00:00"), verbose = TRUE)

# this doesn't work
getBars("AAPL Equity", startTime = as.POSIXct("2022-07-04 15:00:00"), verbose = TRUE)
csrvermaak commented 2 years ago

You have to specify the Exchange code as well (US in the case of Apple).

Try again with this ticker: AAPL US Equity

MislavSag commented 2 years ago

Works with US.

eddelbuettel commented 2 years ago

I think that is a general feature with equity tickers so we can probably close this.