通过Python-Bloomberg API绘制股票行情的ISIN



我有一个关于在python中绘制政府债券ISIN的问题。据我所知,最先进的包装是";blp";在python中,它被描述为pdblp的下一个迭代。我想做的是获得政府股票代码的所有ISIN;DBR Govt";。我知道Excel中存在BQL,它可以做到这一点。在python中无法访问它。

有没有一种方法可以用";blp";?我知道";pdblp";具有一个功能";bsrch";这可以做到,但我无法访问此包。或者还有其他方法可以用另一个包在python中完成任务吗?

谢谢你的一些想法。

@DS_London,感谢您对blp/instruments的关注。我为企业开放API服务&模式参考指南(PDF(,很难找到。我试着再次找到它,但没有找到。在第75页上,我找到了政府的查找请求,并调整了一些现有的代码以使其发挥作用。我已经为这些代码中的一些创建了单独的函数,但我没有为此测试而烦恼。我想这可能会帮助我看看是否有办法从SRCH中提取证券列表,但不确定我是否能做到

编辑:如果你是BBG用户,你可以在WAPI->API开发人员指南->参考指南:服务和架构。

from argparse import ArgumentParser
import blpapi
SESSION_STARTED = blpapi.Name("SessionStarted")
SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure")
# Removed optparse.OptionParser because it was deprecated.
def parseCmdLine():
parser = ArgumentParser(description='Retrieve reference data.')
parser.add_argument('-a',
'--ip',
dest='host',
help='server name or IP (default: %(default)s)',
metavar='ipAddress',
default='localhost')
parser.add_argument('-p',
dest='port',
type=int,
help='server port (default: %(default)s)',
metavar='tcpPort',
default=8194)
args = parser.parse_args()
return args
args = parseCmdLine()
# Fill SessionOptions
sessionOptions = blpapi.SessionOptions()
sessionOptions.setServerHost(args.host)
sessionOptions.setServerPort(args.port)
# Create a Session
session = blpapi.Session(sessionOptions)
# Start a Session
session.start()
session.openService("//blp/instruments")
instrumentsDataService = session.getService("//blp/instruments")
request = instrumentsDataService.createRequest("govtListRequest")
# request.asElement().setElement('partialMatch', True)
request.asElement().setElement('query', 'DBR')
request.asElement().setElement('ticker', '')
request.asElement().setElement('maxResults', 10)
session.sendRequest(request)
try:
# Process received events
while(True):
# We provide timeout to give the chance to Ctrl+C handling:
ev = session.nextEvent(500)
# below msg.messageType == GovtListResponse
for msg in ev:
if msg.messageType() == "GovtListResponse":
if msg.hasElement("responseError"):
print(msg.toString())
if msg.hasElement("results"):
data = msg.getElement("results")
print(data)
# Response completly received, so we could exit
if ev.eventType() == blpapi.Event.RESPONSE:
break
finally:
# Stop the session
session.stop()
>>>results[] = {
results = {
parseky = "BT245031 Corp"
name = "Bundesrepublik Deutschland Bundesanleihe"
ticker = "DBR"
}
results = {
parseky = "BP980366 Corp"
name = "Bundesrepublik Deutschland Bundesanleihe"
ticker = "DBR"
}
results = {
parseky = "BR246981 Corp"
name = "Bundesrepublik Deutschland Bundesanleihe"
ticker = "DBR"
}
results = {
parseky = "BN261261 Corp"
name = "Bundesrepublik Deutschland Bundesanleihe"
ticker = "DBR"
}
results = {
parseky = "AW416188 Corp"
name = "Bundesrepublik Deutschland Bundesanleihe"
ticker = "DBR"
}
results = {
parseky = "ZR097974 Corp"
name = "Bundesrepublik Deutschland Bundesanleihe"
ticker = "DBR"
}
results = {
parseky = "AP115404 Corp"
name = "Bundesrepublik Deutschland Bundesanleihe"
ticker = "DBR"
}
results = {
parseky = "AQ584649 Corp"
name = "Bundesrepublik Deutschland Bundesanleihe"
ticker = "DBR"
}
results = {
parseky = "AL997549 Corp"
name = "Bundesrepublik Deutschland Bundesanleihe"
ticker = "DBR"
}
results = {
parseky = "ZP220656 Corp"
name = "Bundesrepublik Deutschland Bundesanleihe"
ticker = "DBR"
}
}

最新更新