2

我在尝试处理ReferenceDataRequest. 这是我用来填写会话的所有代码。

global options
options = parseCmdLine()
sessionOptions = blpapi.SessionOptions()                                   
sessionOptions.setServerHost(options.host)
sessionOptions.setServerPort(options.port)
session = blpapi.Session(sessionOptions)                            

if not session.start():                                                  
    print ("Failed to start session.")
    return False

if not session.openService("//blp/refdata"):                            
    print ("Failed to open //blp/refdata")
    return False

refDataService = session.getService("//blp/refdata")                   
request = refDataService.createRequest("ReferenceDataRequest")       
request.getElement("securities").appendValue("UX1 Index")             
request.getElement("fields").appendValue("FUT_DAYS_EXPIRE")
cid = session.sendRequest(request)                                    

while(True):                                                            
    ev = session.nextEvent(500)                                         
    for msg in ev:
        if cid in msg.correlationIds():
            # print(msg)
            data = msg.getElement("securityData").getElement("fieldData")

    if ev.eventType() == blpapi.Event.RESPONSE:
            break

print(data)
session.stop()

我收到此错误。blpapi.exception.UnknownErrorException: Attempt access name 'fieldData' on array element 'securityData' (0x00000003).

这是msg收到的样子。

ReferenceDataResponse = {
    securityData[] = {
        securityData = {
            security = "UX1 Index"
            eidData[] = {
            }
            fieldExceptions[] = {
            }
            sequenceNumber = 0
            fieldData = {
                FUT_DAYS_EXPIRE = 27
            }
        }
    }
}

有没有办法解决这个问题?

4

2 回答 2

1

解决方案是缩小msg元素和值的范围。进行了大量测试,但这是我的具体问题的解决方案。

refDataService = session.getService("//blp/refdata")                    
request = refDataService.createRequest("ReferenceDataRequest")         
request.getElement("securities").appendValue("UX1 Index")             
request.getElement("fields").appendValue("FUT_DAYS_EXPIRE")
cid = session.sendRequest(request)                                     
while(True):                                                           
    ev = session.nextEvent(500)                                        
    for msg in ev:      
        if cid in msg.correlationIds():
            data = msg.getElement("securityData").getValue().getElement("fieldData").getElement("FUT_DAYS_EXPIRE").getValue()


    if ev.eventType() == blpapi.Event.RESPONSE:
            break

print(data)
session.stop()

DAPI查看blpapi 目录中提供的示例对我有帮助。

于 2018-06-21T16:11:17.477 回答
0

你也可以做

data = msg.getElement("securityData").getElement("securityData").getElement("fieldData").getElement("FUT_DAYS_EXPIRE").getValue().

我相信 getValue() 有效,因为 securityData[] 数组中只有一个值。

于 2020-11-25T15:32:24.617 回答