blpapipdblp

pdblp.BCon.bdh usage. inserting an array as the "list" argument


The usage for con.bdh is con.bdh('SPY US Equity', ['PX_LAST', 'VOLUME'], '20150629', '20150630', longdata=True)

I would like to get PX_LAST and VOLUME for a list of securities that I have on an array (strings with tickers). When I try to substitute SPY US Equity with the array "arrtickers" or [list(arrtickers)] I get the following error:

 ...eidData[] = {
    }
    sequenceNumber = 0
    securityError = {
        source = "3920::bbdbh4"
        code = 15
        category = "BAD_SEC"
        message = "Security key is too longInvalid Security [nid:3920] "
        subcategory = "INVALID_SECURITY"
    }
    fieldExceptions[] = {
    }
    fieldData[] = {
}}}

Am I using the correct syntax?


Solution

  • Without posting a reproducible example this is just a guess, but as the error message in your snippet suggests this is likely because you are querying for an invalid security. Array syntax should work. For example the following works fine

    In [1]: import pdblp
       ...: con = pdblp.BCon().start()
       ...: con.bdh(['SPY US Equity', 'IBM US Equity'], ['PX_LAST', 'VOLUME'],
                    '20150629', '20150630', longdata=True)
    Out[1]
            date         ticker    field         value
    0 2015-06-29  SPY US Equity  PX_LAST  2.054200e+02
    1 2015-06-29  SPY US Equity   VOLUME  2.026213e+08
    2 2015-06-30  SPY US Equity  PX_LAST  2.058500e+02
    3 2015-06-30  SPY US Equity   VOLUME  1.829251e+08
    4 2015-06-29  IBM US Equity  PX_LAST  1.629700e+02
    5 2015-06-29  IBM US Equity   VOLUME  3.314684e+06
    6 2015-06-30  IBM US Equity  PX_LAST  1.626600e+02
    7 2015-06-30  IBM US Equity   VOLUME  3.597288e+06
    

    Whereas this does not

    In [2]: con.bdh(['SPY US Equity', 'NOT_A_SECURITY Equity'], ['PX_LAST', 'VOLUME'],
                    '20150629', '20150630', longdata=True)
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    <ipython-input-5-f23344f8a6b3> in <module>()
    ----> 1 con.bdh(['SPY US Equity', 'NOT_A_SECURITY Equity'], ['PX_LAST', 'VOLUME'], '20150629', '20150630', longdata=True)
    
    ~/Projects/pdblp/pdblp/pdblp.py in bdh(self, tickers, flds, start_date, end_date, elms, ovrds, longdata)
        268 
        269         data = self._bdh_list(tickers, flds, start_date, end_date,
    --> 270                               elms, ovrds)
        271 
        272         df = pd.DataFrame(data, columns=["date", "ticker", "field", "value"])
    
    ~/Projects/pdblp/pdblp/pdblp.py in _bdh_list(self, tickers, flds, start_date, end_date, elms, ovrds)
        305                                    .numValues() > 0)
        306             if has_security_error or has_field_exception:
    --> 307                 raise ValueError(msg)
        308             ticker = (msg.getElement('securityData')
        309                       .getElement('security').getValue())
    
    ValueError: HistoricalDataResponse = {
        securityData = {
            security = "NOT_A_SECURITY Equity"
            eidData[] = {
            }
            sequenceNumber = 1
            securityError = {
                source = "139::bbdbh3"
                code = 15
                category = "BAD_SEC"
                message = "Unknown/Invalid securityInvalid Security [nid:139] "
                subcategory = "INVALID_SECURITY"
            }
            fieldExceptions[] = {
            }
            fieldData[] = {
            }
        }
    }