Assuming that we are sending Bloomberg Historical data request for multiple securities using .Net API, is there any elegant way to separate/identify response data of each security?
I am aware that there is a field sequenceNumber
in the response but not sure how it is mapped to each security. My code snippet is given below.
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?();
}
}
}
}
Bloomberg Server API (SAPI) delivers a powerful complement to the Bloomberg Terminal. SAPI allows you to consume Bloomberg's unique real-time market, historical, and key reference data, as well as calculation engine capabilities when using proprietary and third-party applications.
NOTE: Bloomberg is offering this programming interface (BLPAPI) under a free-use license. This license does not include nor provide access to any Bloomberg data or content.
BLPAPI PROGRAMMING INTERFACE Subscription services are used to receive data that changes frequently and/or at unpredictable intervals, for example equity pricing data or order-fill notifications.
The sequenceNumber
value that is returned corresponds to the order in which you added the securities with the call to 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
As per the BLPAPI: Developer’s Guide:
Security sequence number, specifying the position of the security in the request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With