从bloomberg api获取批量数据

时间:2018-02-22 16:09:42

标签: c# bloomberg

在PX_LAST上发出一个月的HistoricalDataRequest请求时,我将收回批量数据。我的语法出了什么问题,因为我不断收到“无法将SEQUENCE转换为元素”。

 //FIELDS
                Element fields = security.GetElement(FIELD_DATA);
                if (fields.NumElements > 0)
                {
                    int numElements = fields.NumElements;
                    for (int j = 0; j < numElements; ++j)
                    {
                        Element field = fields.GetElement(j);

                        if (field.Datatype == Schema.Datatype.SEQUENCE || field.IsArray)
                        {
                            processBulkField(field, ticker, response);
                        }
                        else
                        {
                            processRefField(field, ticker, response);
                        }


                    }
                }

这里是进程批量字段:错误在行:Element bulkElement = refBulkfield.GetValueAsElement(i);

 private static void processBulkField(Element refBulkfield, string ticker, List<BBGSecurity> response)
    {
        // Get the total number of Bulk data points
        int numofBulkValues = refBulkfield.NumValues;

        for (int i = 0; i < numofBulkValues; ++i)
        {
            Element bulkElement = refBulkfield.GetValueAsElement(i);

            // Get the number of sub fields for each bulk data element
            int numofBulkElements = bulkElement.NumElements;

            // Read each field in Bulk data
            for (int j = 0; j < numofBulkElements; ++j)
            {
                Element field = bulkElement.GetElement(j);

                response.Add(new BBGSecurity { Security = ticker, DataDate = DateTime.Parse(d_dataDate), DataSessionID = d_dataSession, Field = field.Name.ToString(), PropertyValue = field.GetValueAsString() });

            }


        }
    }

提前致谢!

1 个答案:

答案 0 :(得分:0)

请从field.Datatype == Schema.Datatype.SEQUENCE条件中移除if,它应如下所示:

if (field.IsArray)
{
    processBulkField(field, ticker, response);
}
else
{
    processRefField(field, ticker, response);
}

批量字段由属性field.IsArray = True标识。 批量字段包含结构化为包含列和行的表的数据集,而SEQUENCE字段包含表示为C结构的数据集。