我有一个问题,关于如何在python中绘制政府键的ISIN。据我所知,这个最先进的软件包是python中的"blp“,它被描述为pdblp的下一个迭代。我想做的是得到所有的ISIN的一个政府代码,如"DBR“。我知道在Excel中存在这样的情况。在python中没有访问它的权限。
有没有办法用"blp“来完成这个任务?我知道"pdblp“有一个函数"bsrch”可以做到这一点,但是我无法访问这个包。或者还有其他方法可以用另一个包在python中完成我的任务?
谢谢你的一些想法。
发布于 2022-06-24 14:28:28
@DS_London,谢谢你让我看看blp/仪器。我深入研究了彭博企业开放API服务和模式参考指南(PDF),这很难找到。我想再找一次,但没有运气。在第75页上,我找到了政府的查找请求,并对我现有的一些代码进行了修改,以使其正常工作。我已经为其中的一些代码创建了单独的函数,但我没有费心于这个测试。我想这可能会帮助我看看是否有办法从SRCH中提取一份证券清单,但不确定我是否能做到这一点。
编辑:如果您是BBG用户,您可以在WAPI开发人员指南-> ->参考指南:服务和模式中找到上面引用的PDF。
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"
}
}https://stackoverflow.com/questions/71822130
复制相似问题