pdblp.BCon.bdh的用法。将数组作为“列表”参数插入

时间:2018-12-18 21:16:09

标签: blpapi pdblp

con.bdh的使用量为con.bdh('SPY US Equity', ['PX_LAST', 'VOLUME'], '20150629', '20150630', longdata=True)

我想获得PX_LASTVOLUME来获取我在数组中拥有的证券列表(带有代码的字符串)。当我尝试用数组“ arrtickers”或[list(arrtickers)]代替SPY US Equity时,出现以下错误:

 ...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[] = {
}}}

我使用的语法正确吗?

2 个答案:

答案 0 :(得分:0)

在没有发布reproducible example的情况下,这只是一个猜测,但是正如您代码段中的错误消息所暗示的,这很可能是因为您正在查询无效的安全性。数组语法应该起作用。例如,以下工作正常

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

这不是

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[] = {
        }
    }
}

答案 1 :(得分:0)

感谢@mgilbert。我最终创建了一个列表,并将所有报价添加到该列表中。