matthewgilbert / pdblp

pandas wrapper for Bloomberg Open API
MIT License
241 stars 68 forks source link

Intraday can't resolve if datarange has no tickers #63

Open gflores87 opened 5 years ago

gflores87 commented 5 years ago

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

matthewgilbert commented 5 years ago

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.

gflores87 commented 5 years ago

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