彭博API请求超时 - python

发布于 2025-01-20 18:22:03 字数 1916 浏览 3 评论 0原文

我是彭博终端用户,无法与Python Bloomberg API建立连接。

我能够像彭博帮助页面上所述的那样安装BLPAPI软件包,并尝试导入XBBG软件包以获取一些数据。

href =“

import blpapi
from xbbg import blp

blp.bdp(tickers='NVDA US Equity', flds=['Security_Name', 'GICS_Sector_Name'])

https://pypi.org/project/xbbg/”出现以下错误消息:

12APR2022_15:07:37.756 33312:20836 ERROR blpapi_metadatamanagerimpl.cpp:247 blpapi.session.metadatamanager.{1} Resolve request timed out { RequestId=NULL }  
Traceback (most recent call last):
  File "C:\DevLab\MyMainEnv\lib\site-packages\IPython\core\interactiveshell.py", line 3361, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-16-83038899ddda>", line 5, in <cell line: 5>
    blp.bdp(tickers='NVDA US Equity', flds=['Security_Name', 'GICS_Sector_Name'])
  File "C:\DevLab\MyMainEnv\lib\site-packages\xbbg\blp.py", line 47, in bdp
    request = process.create_request(
  File "C:\DevLab\MyMainEnv\lib\site-packages\xbbg\core\process.py", line 47, in create_request
    req = srv.createRequest(request)
  File "C:\DevLab\MyMainEnv\lib\site-packages\blpapi\service.py", line 393, in createRequest
    _ExceptionUtil.raiseOnError(errCode)
  File "C:\DevLab\MyMainEnv\lib\site-packages\blpapi\exception.py", line 143, in raiseOnError
    _ExceptionUtil.raiseException(errorCode, description)
  File "C:\DevLab\MyMainEnv\lib\site-packages\blpapi\exception.py", line 135, in raiseException
    raise errorClass(description, errorCode)
blpapi.exception.InvalidArgumentException: Null service handle (0x00020002)
'blpapi' in sys.modules 
'xbbg' in sys.modules

给我true

,而

'blp' in sys.modules

给我false

有什么想法发生此错误?

I am a Bloomberg Terminal user and can't establish a connection with the Python Bloomberg API.

I was able to install the blpapi package like described on the Bloomberg help page and tried to import the xbbg package to get some data.

https://www.bloomberg.com/professional/support/api-library/

https://pypi.org/project/xbbg/

When I run this:

import blpapi
from xbbg import blp

blp.bdp(tickers='NVDA US Equity', flds=['Security_Name', 'GICS_Sector_Name'])

the following error message appears:

12APR2022_15:07:37.756 33312:20836 ERROR blpapi_metadatamanagerimpl.cpp:247 blpapi.session.metadatamanager.{1} Resolve request timed out { RequestId=NULL }  
Traceback (most recent call last):
  File "C:\DevLab\MyMainEnv\lib\site-packages\IPython\core\interactiveshell.py", line 3361, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-16-83038899ddda>", line 5, in <cell line: 5>
    blp.bdp(tickers='NVDA US Equity', flds=['Security_Name', 'GICS_Sector_Name'])
  File "C:\DevLab\MyMainEnv\lib\site-packages\xbbg\blp.py", line 47, in bdp
    request = process.create_request(
  File "C:\DevLab\MyMainEnv\lib\site-packages\xbbg\core\process.py", line 47, in create_request
    req = srv.createRequest(request)
  File "C:\DevLab\MyMainEnv\lib\site-packages\blpapi\service.py", line 393, in createRequest
    _ExceptionUtil.raiseOnError(errCode)
  File "C:\DevLab\MyMainEnv\lib\site-packages\blpapi\exception.py", line 143, in raiseOnError
    _ExceptionUtil.raiseException(errorCode, description)
  File "C:\DevLab\MyMainEnv\lib\site-packages\blpapi\exception.py", line 135, in raiseException
    raise errorClass(description, errorCode)
blpapi.exception.InvalidArgumentException: Null service handle (0x00020002)
'blpapi' in sys.modules 
'xbbg' in sys.modules

gives me True

while

'blp' in sys.modules

gives me False

any ideas why this error occurs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽清梦 2025-01-27 18:22:03

这不是答案,而是某些诊断代码以隔离错误是来自彭博(blpapi)还是使用此API的xbbg包装器。

它显示了如何在没有xbbg的情况下在API级别访问彭博数据。如果此代码成功运行,则您的彭博连接很好,问题是XBBG,反之亦然。

import blpapi

sessionOptions = blpapi.SessionOptions()
sessionOptions.setServerHost('localhost')
sessionOptions.setServerPort(8194)

session = blpapi.Session(sessionOptions)

session.start()

if session.openService('//blp/refdata'):
    svc = session.getService('//blp/refdata')

    req = svc.createRequest('ReferenceDataRequest')

    req.append('securities','NVDA US Equity')
    req.append('fields','SECURITY_NAME')
    req.append('fields','GICS_SECTOR_NAME')

    session.sendRequest(req)

    results = None

    while(True):
        ev = session.nextEvent()

        if ev.eventType() == blpapi.Event.RESPONSE:
            for msg in ev:
                for elt in msg.asElement():
                    results = { e.getElementValue('security'): 
                                 { str(f.name()) : f.getValueAsString() 
                                     for f in e.getElement('fieldData') } 
                               for e in elt }
            break

    print(results)

输出应该是:

{'NVDA US Equity': {'SECURITY_NAME': 'NVIDIA Corp', 'GICS_SECTOR_NAME': 'Information Technology'}}

这本质上是XBBG调用bdp()时正在做的事情,并测试基本的彭博API是否正在工作。

This is not an answer, but some diagnostic code to isolate whether the error is coming from Bloomberg (blpapi) or the xbbg wrapper that uses this API.

It shows how to access Bloomberg data at the API level, without xbbg. If this code runs successfully then your Bloomberg connection is fine, and the problem is with xbbg, and vice-versa.

import blpapi

sessionOptions = blpapi.SessionOptions()
sessionOptions.setServerHost('localhost')
sessionOptions.setServerPort(8194)

session = blpapi.Session(sessionOptions)

session.start()

if session.openService('//blp/refdata'):
    svc = session.getService('//blp/refdata')

    req = svc.createRequest('ReferenceDataRequest')

    req.append('securities','NVDA US Equity')
    req.append('fields','SECURITY_NAME')
    req.append('fields','GICS_SECTOR_NAME')

    session.sendRequest(req)

    results = None

    while(True):
        ev = session.nextEvent()

        if ev.eventType() == blpapi.Event.RESPONSE:
            for msg in ev:
                for elt in msg.asElement():
                    results = { e.getElementValue('security'): 
                                 { str(f.name()) : f.getValueAsString() 
                                     for f in e.getElement('fieldData') } 
                               for e in elt }
            break

    print(results)

The output should be:

{'NVDA US Equity': {'SECURITY_NAME': 'NVIDIA Corp', 'GICS_SECTOR_NAME': 'Information Technology'}}

This is essentially what xbbg is doing when you call bdp(), and tests whether the basic Bloomberg API is working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文