假设我们使用.Net API向多个证券发送Bloomberg历史数据请求,是否有任何优雅的方法来分离/识别每个证券的响应数据。我知道响应中有一个字段'sequenceNumber'但是不确定它是如何映射到每个安全性的。我的代码片段如下。
Service refDataService = session.GetService("//blp/refdata");
Request request = refDataService.CreateRequest("HistoricalDataRequest");
Element securities = request.GetElement("securities");
securities.AppendValue("EURUSD CURNCY");
securities.AppendValue("USDJPY CURNCY");
securities.AppendValue("GBPUSD Curncy");
securities.AppendValue("USDCHF Curncy");
Element fields = request.GetElement("fields");
fields.AppendValue("OPEN");
fields.AppendValue("HIGH");
fields.AppendValue("LOW");
fields.AppendValue("PX_LAST");
request.Set("periodicityAdjustment", "CALENDAR");
request.Set("periodicitySelection", "DAILY");
request.Set("startDate", DateTime.Now.AddDays(-30).ToString("yyyyMMdd"));
request.Set("endDate", Convert.ToString(null));
session.SendRequest(request, null);
while (true)
{
Event eventObj = session.NextEvent();
foreach (Message msg in eventObj.GetMessages())
{
if (msg.MessageType.Equals(Name.GetName("HistoricalDataResponse")))
{
Element secDataArray = msg.GetElement("securityData");
Element securityData = secDataArray.GetElement(3);
for (int index = 0; index < securityData.NumValues; index++)
{
Element fieldData = securityData.GetValueAsElement(index);
Datetime time = fieldData.GetElementAsDate("date");
decimal? open = fieldData.HasElement("OPEN") ? Convert.ToDecimal(fieldData.GetElementAsFloat64("OPEN")) : new decimal?();
decimal? high = fieldData.HasElement("HIGH") ? Convert.ToDecimal(fieldData.GetElementAsFloat64("HIGH")) : new decimal?();
decimal? low = fieldData.HasElement("LOW") ? Convert.ToDecimal(fieldData.GetElementAsFloat64("LOW")) : new decimal?();
decimal? close = fieldData.HasElement("PX_LAST") ? Convert.ToDecimal(fieldData.GetElementAsFloat64("PX_LAST")) : new decimal?();
}
}
}
}
答案 0 :(得分:4)
返回的sequenceNumber
值对应于您通过调用AppendValue
securities.AppendValue("EURUSD CURNCY"); // Sequence number 1
securities.AppendValue("USDJPY CURNCY"); // Sequence number 2
securities.AppendValue("GBPUSD Curncy"); // Sequence number 3
securities.AppendValue("USDCHF Curncy"); // Sequence number 4
安全序列号,指定请求中安全性的位置。
答案 1 :(得分:2)
你可能还需要一个循环:
foreach (Message msg in eventObj.GetMessages())
{
Element element = msg.GetElement("securityData");
for (int i = 0; i < element.NumValues; i++)
{
Element security = element.GetValueAsElement(i);
string ticker = security.GetElementAsString("security");
Element fields = security.GetElement("fieldData");
decimal px_last = Convert.toDecimal(fields.GetElementAsFloat64("PX_LAST"));
}
}
答案 2 :(得分:0)
在Java中(易于转换):
Element securityData = msg.getElement("securityData");
String ticker = securityData.getElementAsString("security");
答案 3 :(得分:0)
您可以从$(".item").css("height","0");
if (selector.length) {
$('.item.'+ selector.join('.')).css("height", "15px");
}
元素中提取Bloomberg代码,如下所示:
securityData