Как я могу преобразовать ответное сообщение, возвращенное с помощью API Bloomberg в (python3 и flask), в JSON
here is a response example:
ReferenceDataResponse = {
securityData[] = {
securityData = {
security = "FB EQUITY"
eidData[] = {
}
fieldExceptions[] = {
}
sequenceNumber = 0
fieldData = {
PX_LAST = 186.270000
VOLUME = 16746904.000000
}
}
securityData = {
security = "IBM EQUITY"
eidData[] = {
}
fieldExceptions[] = {
}
sequenceNumber = 1
fieldData = {
PX_LAST = 134.400000
VOLUME = 2551009.000000
}
}
}
}
справиться с этим с помощью следующего фрагмента кода:
if str(msg.messageType()) == "ReferenceDataResponse":
securities = msg.getElement('securityData')
securities_count = securities.numValues()
for i in range(securities_count):
security = securities.getValueAsElement(i)
ticker = security.getElementAsString('security')
if (security.hasElement('fieldData')):
fields = security.getElement('fieldData')
fields_count = fields.numElements()
for j in range (fields_count):
security_dict = None
field = fields.getElement(j)
f_name = field.name()
f_value = field.getValueAsString()
security_dict = {"ticker":ticker ,"f_name":f_name , "f_value":f_value}
bloom_data.append(security_dict)
дайте мне (объект типа Name не сериализуем JSON) теперь я не могу не получить доступ к объекту имени, чтобы получить имя полей, любая помощь будет очень признательна
f_name = field.name()
, которая возвращает объектName
, а не строку. В Java вы бы сделалиfield.name().toString()
, чтобы получить базовую строку - я полагаю, что в Python есть аналогичная функция. - person assylias   schedule 20.05.2019