我从 BBG 开始为 Python 开发 BLPAPI。我让它工作了。现在我得到了市场数据输出,但我不知道如何正确处理它们(我什至不知道这是什么数据)。编码:
def main():
options = parseCmdLine()
# Fill SessionOptions
sessionOptions = blpapi.SessionOptions()
sessionOptions.setServerHost(options.host)
sessionOptions.setServerPort(options.port)
print("Connecting to %s:%d" % (options.host, options.port))
# Create a Session
session = blpapi.Session(sessionOptions)
# Start a Session
if not session.start():
print("Failed to start session.")
return
if not session.openService("//blp/mktdata"):
print("Failed to open //blp/mktdata")
return
security1 = "IBM US Equity"
#security2 = "/cusip/912828GM6@BGN"
subscriptions = blpapi.SubscriptionList()
subscriptions.add(security1,
"LAST_PRICE,BID,ASK",
"",
blpapi.CorrelationId(security1))
session.subscribe(subscriptions)
try:
# Process received events
eventCount = 0
while(True):
# We provide timeout to give the chance to Ctrl+C handling:
event = session.nextEvent(100)
for msg in event:
if event.eventType() == blpapi.Event.SUBSCRIPTION_STATUS or \
event.eventType() == blpapi.Event.SUBSCRIPTION_DATA:
print(msg)
if event.eventType() == blpapi.Event.SUBSCRIPTION_DATA:
eventCount += 1
if eventCount >= options.maxEvents:
break
输出:
IBM US Equity
02MAY2020_11:59:47.298 1424:22272 WARN blpapi_selfdescvalueelementimpl.cpp:846 SelfDescValueElementImpl Invalid dateortime wire value: 20121301
MarketDataEvents = {
MKTDATA_EVENT_TYPE = SUMMARY
MKTDATA_EVENT_SUBTYPE = INITPAINT
BID = 121.820000
ASK = 121.830000
BEST_BID = 121.820000
BEST_ASK = 121.830000
BID_ALL_SESSION = 121.750000
ASK_ALL_SESSION = 121.960000
BID_SIZE_ALL_SESSIONS_RT = 4
ASK_SIZE_ALL_SESSIONS_RT =
所以我的问题是我怎样才能获得例如:每次事件更新时的 BEST_BID,所以我得到一个以 121.820000 为数字的变量。