pdblp icon indicating copy to clipboard operation
pdblp copied to clipboard

Intraday can't resolve if datarange has no tickers

Open gflores87 opened this issue 5 years ago • 2 comments

Code Sample, a copy-pastable example if possible


equity = con.bdib('SPX Index', '2019-04-19T01:00:00', '2019-04-22T21:00:00', 'TRADE', 1)

Problem description

As of April 22nd at 8:03EST, the request for the intraday trade prints for SPX Index is empty. There's nothing wrong with that, the issue here is that the code won't return an empty dataset. Instead it will crash. Specifically, it will crash trying to execute this line from file pdblp.py, method bdib:

data = pd.DataFrame(data).set_index('time').sort_index().loc[:, flds]

Error raised:

KeyError: 'time'

This is the content from debug = True

pdblp.pdblp:INFO:Sending Request:
IntradayBarRequest = {
    security = "SPX Index"
    eventType = TRADE
    interval = 1
    startDateTime = 2019-04-19T01:00:00
    endDateTime = 2019-04-22T21:00:00
}

pdblp.pdblp:INFO:Event Type: 'RESPONSE'
pdblp.pdblp:INFO:Message Received:
IntradayBarResponse = {
    barData = {
        eidData[] = {
        }
        barTickData[] = {
        }
    }
}

Expected Output

equity = []

Version Information

0.1.8

gflores87 avatar Apr 22 '19 12:04 gflores87

Yes this looks like a bug. Another issue with this is that IntradayBarRequest can set overrides to update the number of fields returned so by selecting with the preset flds = ['open', 'high', 'low', 'close', 'volume', 'numEvents'] these extra fields would be ignored.

matthewgilbert avatar Apr 22 '19 14:04 matthewgilbert

Appreciate the feedback. I took the liberty to change my code for bdib to this:

        if len(data) == 0:
            data = pd.DataFrame()
        else:
            data = pd.DataFrame(data).set_index('time').sort_index().loc[:, flds]
        return data

this way, it won't crash on an empty data

gflores87 avatar Apr 22 '19 14:04 gflores87