python - TIA Bloomberg 请求处理无效代码

标签 python pandas bloomberg

我有以下内容:

import blpapi
import pandas as pd
from tia.bbg import LocalTerminal
import tia.bbg.datamgr as dm



mgr = dm.BbgDataManager()

tickers = mgr['GLEN LN EQUITY', 'AAPL US EQUITY',"a"] 

df = tickers.get_historical('PX_LAST', start = '31/1/2019', end = 
           '31/1/2019', currency='EUR')

由于“a”显然不是有效的股票代码,我收到以下错误:

raise Exception('SecurityError: %s' % ','.join(msgs))

Exception: SecurityError: (a, BAD_SEC, Null/Blank Security String [nid:191] 

处理潜在无效代码的最佳方法是什么?

我已经尝试过:

try:
    df = tickers.get_historical('PX_LAST', start = '31/1/2019', end = 
            '31/1/2019', currency='EUR')
except Exception:
     print("Could not validate ticker:")

但这会完全停止请求并且不会提供任何有效的返回,实际上它表示“df”未定义。

如果“a”不在代码中,则输出为:

                 GLEN LN EQUITY  AAPL US EQUITY
date                                      
2019-01-31         3.54638       145.36245 

理想情况下,我希望完全跳过无效的代码,并且输出与最初不存在的情况相同,即与上面相同。

最佳答案

找到答案:ignore_security_error=1

df = tickers.get_historical('PX_LAST', start = '31/1/2019', end = 
        '31/1/2019', currency='EUR', ignore_security_error=1) 

忽略任何不良代码。

关于python - TIA Bloomberg 请求处理无效代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54706564/

相关文章:

excel - 从 VBA 中的类模块中提取特定变量到标准模块

vba - 在 for 循环 VBA 中刷新 Bloomberg 请求

python - 在使用 django-filter 进行过滤时如何将过滤后的值导出到 csv 文件中

python - 帮助使用具有多个文件夹的 Python setup.py

python - 属性错误 : 'str' object has no attribute 'xpath'

Python将列表作为参数传递

python - 更新数据框 ID w.r.t 缺少日期列值

python - Pandas :分别对每一列进行排序

python - 如何使用 Python pdblp 的 CSV 文件而不是股票引用来从 con.ref 获取 API

python - 在 Python 中使用正则表达式来排除字符串