使用Bloomberg blpapi获取每日收盘价的许可与部署咨询
Bloomberg Data License + Python blpapi 配置指南(收盘价获取场景)
一、所需许可与产品
- 核心许可:你当前拥有的Bloomberg Data License (BDL) 完全满足需求,无需额外购买Bloomberg Terminal等终端类许可。BDL专为批量自动化数据获取设计,适配每日收盘价抓取的场景。
- 依赖工具:
- Python 3.7及以上版本(兼容性最优)
- Bloomberg官方提供的BDL专用
blpapiPython包
二、完整部署配置步骤
1. 安装blpapi Python包
BDL用户需使用专属源安装,不要用公开PyPI源。执行以下命令:
pip install blpapi --index-url=https://bloomberg.bintray.com/pip/simple
注:此版本已内置底层依赖,无需单独安装C++ SDK。
2. 获取并配置BDL连接参数
联系你的Bloomberg客户经理获取以下必填信息:
- BDL账户ID
- 加密密钥文件(
.pem格式,若需) - BDL专用数据网关地址与端口(通常端口为8194)
- 需将GCP实例的公网IP提交给Bloomberg,加入网关访问白名单
3. 编写基础收盘价获取代码
以下是最小可用示例(单日单标的):
import blpapi import datetime # 初始化会话配置 session_options = blpapi.SessionOptions() session_options.setServerHost("你的BDL网关地址") session_options.setServerPort(8194) # 以客户经理提供的端口为准 session_options.setAuthenticationOptions(blpapi.AuthenticationOptions()) session_options.authenticationOptions().setAuthOptions({ "authenticationType": "OS_LOGON", "userId": "你的BDL账户ID", "ipAddress": "你的GCP实例公网IP" }) # 启动会话 session = blpapi.Session(session_options) if not session.start(): print("会话启动失败,请检查配置") exit() # 构建历史数据请求 request = session.createRequest("HistoricalDataRequest") request.set("startDate", datetime.date.today().strftime("%Y%m%d")) request.set("endDate", datetime.date.today().strftime("%Y%m%d")) request.set("periodicityAdjustment", "ACTUAL") request.set("periodicitySelection", "DAILY") # 添加标的与字段 securities = request.getElement("securities") securities.appendValue("AAPL US Equity") # 替换为你的目标标的 fields = request.getElement("fields") fields.appendValue("PX_LAST") # 收盘价字段 # 发送请求并解析响应 session.sendRequest(request) while True: event = session.nextEvent() for msg in event: if event.eventType() in (blpapi.Event.RESPONSE, blpapi.Event.PARTIAL_RESPONSE): security_data = msg.asElement().getElement("securityData") print(f"标的: {security_data.getElementAsString('security')}") for field in security_data.getElement("fieldData").values(): print(f"当日收盘价: {field.getElementAsFloat('PX_LAST')}") if event.eventType() == blpapi.Event.RESPONSE: break session.stop()
4. GCP部署要点
- 确保GCP实例的出站防火墙规则允许访问BDL网关的端口(如8194)
- 后续可通过GCP Cloud Scheduler+Cloud Function/Compute Engine实现工作日自动运行(此部分可后续单独配置)
三、常见疑问澄清
- 无需安装Bloomberg Terminal:BDL是独立许可体系,所有数据交互通过API完成,不需要安装任何终端客户端
- 无需手动安装C++ SDK:BDL专属的
blpapi包已打包所有底层依赖,pip安装后即可直接使用 - 白名单要求:BDL网关仅允许报备过的IP访问,必须提前将GCP实例IP提交给Bloomberg
内容的提问来源于stack exchange,提问作者Tejas
相关产品推荐
相关产品推荐

