Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bloomberg .Net API - Response Data for Multiple Securities

Tags:

c#

.net

bloomberg

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?();
        }
    }
}
}
like image 583
Ravinder Singh Avatar asked Sep 07 '12 09:09

Ravinder Singh


People also ask

Does Bloomberg offer API?

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.

Is Bloomberg Open API free?

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.

What is Blpapi?

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.


1 Answers

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.

like image 185
casperOne Avatar answered Sep 24 '22 09:09

casperOne