matthewgilbert / pdblp

pandas wrapper for Bloomberg Open API
MIT License
240 stars 69 forks source link

pdblp does not handle responseError in ReferenceDataResponse #74

Open shjin404 opened 4 years ago

shjin404 commented 4 years ago

Code Sample

fun = blpcon.ref(securities, fundamental_fields, [('EQY_FUND_RELATIVE_PERIOD', relativePeriod)])

Problem description

When daily limit has reached, I get TypeError: string indices must be integers

~\.conda\envs\myconda36\lib\site-packages\pdblp\pdblp.py in ref(self, tickers, flds, ovrds)
    362         logger.info('Sending Request:\n{}'.format(request))
    363         self._session.sendRequest(request, identity=self._identity)
--> 364         data = self._parse_ref(flds)
    365         data = pd.DataFrame(data)
    366         data.columns = ['ticker', 'field', 'value']

~\.conda\envs\myconda36\lib\site-packages\pdblp\pdblp.py in _parse_ref(self, flds, keep_corrId, sent_events)
    377             d = msg['element']['ReferenceDataResponse']
    378             for security_data_dict in d:
--> 379                 secData = security_data_dict['securityData']
    380                 ticker = secData['security']
    381                 if 'securityError' in secData:

TypeError: string indices must be integers

When enabling debug, this is trace:

pdblp.pdblp:INFO:Event Type: 'PARTIAL_RESPONSE'
pdblp.pdblp:INFO:Message Received:
ReferenceDataResponse = {
    responseError = {
        source = "bbdbd2"
        code = -4001
        category = "LIMIT"
        message = "uuid: xxxxxxx, SN: xxxxx, sid: xxxxx Daily capacity reached. [nid:xxxx] "
        subcategory = "DAILY_CAPACITY_REACHED"
    }
}

Expected Output

It would be great if _parse_ref() function can understand the PARTIAL_RESPONSE event type and report actual error rather than TypeError which is hiding underlying error.

Version Information

[paste the output of pdblp.__version__ here below this line] '0.1.8'

Thank you

Thank you for awesome library.

matthewgilbert commented 4 years ago

I agree this would be a nice feature to have but will likely not have the time to implement this in the foreseable future. Currently the parsing of the responses happens throughout the library instead of in a centralized place, so implementing this check would be a bit involved. To test would also involve adding mocking since these responses can only be replicated when your limits are hit.

shjin404 commented 4 years ago

Thanks. At least I have some fixes that I have currently sprinkled the error checking and it worked fine for my use. I will send a pull request on your way soon.

shjin404 commented 4 years ago

Just sent a new pull request. I am trying to figure out how to link the pull request with this issue. I am completely new to Github workflow.