Example #1
0
        private List <T> ParseEvent_OLD(BbergAPI.Event response, List <T> outputContainer)
        {
            foreach (BbergAPI.Message message in response.GetMessages())
            {
                // Extract security
                BbergAPI.Element security   = message.GetElement(SECURITY_DATA);
                string           currentSec = (string)security.GetElementAsString(TICKER);

                // Extract fields
                BbergAPI.Element fields = security.GetElement(FIELD_DATA);

                int sequenceNumber = security.GetElementAsInt32(SEQUENCE_NUMBER);

                Dictionary <string, int> skipFields = this.initializeSkipFields();

                // Loop through all observation dates
                for (int i = 0; i < fields.NumValues; i++)
                {
                    // Determine type of <T> and create instance
                    var Ttype    = typeof(T);
                    var thisLine = (T)Activator.CreateInstance(Ttype);

                    // extract all field data for a single observation date
                    BbergAPI.Element observationDateFields = fields.GetValueAsElement(i);

                    string   currentStringDate = observationDateFields.GetElementAsString(DATE);
                    DateTime currentDate       = DateTime.ParseExact(currentStringDate, "yyyy-MM-dd", CultureInfo.CurrentCulture);

                    // Determine type of <T> and create instance
                    thisLine.SetDate(currentDate);
                    thisLine.SetDBID(dbid);

                    // Fill the line
                    skipFields = thisLine.SetFromBloomberg(ref observationDateFields, skipFields);

                    // Add to output container
                    outputContainer.Add(thisLine);
                }
            }

            // This kills the data inside the response object...
            this.CloseConnection();

            return(outputContainer);
        }
        public List <String> SearchTicker(String ticker)
        {
            List <String> listTicker = new List <string>();

            // request.AsElement.SetElement("partialMatch", true);
            request.AsElement.SetElement("query", ticker);// this plus the previous line permits to retrieve all the thicker that begins with T
            request.AsElement.SetElement("languageOverride", "LANG_OVERRIDE_NONE");
            request.AsElement.SetElement("maxResults", 10);
            session.SendRequest(request, null);

            bool done = false;

            while (!done)
            {
                // Grab the next Event object
                Event eventObject = session.NextEvent();
                // If this event type is Response then process the messages
                if (eventObject.Type == Event.EventType.RESPONSE)
                {
                    // Loop over all of the messages in this Event
                    foreach (Message msg in eventObject.GetMessages())
                    {
                        Console.WriteLine(msg);
                        Element secDataArray = msg.GetElement("results");

                        for (int index = 0; index < secDataArray.NumValues - 1; index++)
                        {
                            Element fieldData = secDataArray.GetValueAsElement(index);
                            if (fieldData.HasElement("security"))
                            {
                                listTicker.Add(fieldData.GetElementAsString("security"));
                            }
                        }
                    }
                    done = true;
                }
            }

            return(listTicker);
        }
Example #3
0
        private List <T> ParseEvent(BbergAPI.Event response, List <T> outputContainer)
        {
            foreach (BbergAPI.Message message in response.GetMessages())
            {
                // Extract security
                BbergAPI.Element security   = message.GetElement(SECURITY_DATA);
                string           currentSec = (string)security.GetElementAsString(TICKER);

                // Extract fields
                BbergAPI.Element fields = security.GetElement(FIELD_DATA);

                int sequenceNumber = security.GetElementAsInt32(SEQUENCE_NUMBER);

                // Loop through all observation dates
                for (int i = 0; i < fields.NumValues; i++)
                {
                    // Determine type of <T> and create instance
                    var Ttype    = typeof(T);
                    var thisLine = (T)Activator.CreateInstance(Ttype);

                    // extract all field data for a single observation date
                    BbergAPI.Element observationDateFields = fields.GetValueAsElement(i);

                    string   currentStringDate = observationDateFields.GetElementAsString(DATE);
                    DateTime currentDate       = DateTime.ParseExact(currentStringDate, "yyyy-MM-dd", CultureInfo.CurrentCulture);

                    // Set the date and DBID to identify the line
                    thisLine.SetDate(currentDate);
                    thisLine.SetDBID(dbid);

                    // Fill the line with data
                    foreach (string localKey in this.fieldNames.Keys)
                    {
                        if (skip[localKey] < 10000)
                        {
                            try
                            {
                                // Warning : Bloomberg displays interest rates in percentage terms
                                thisLine[localKey] = scaling[localKey] * (double)observationDateFields.GetElementAsFloat64(fieldNames[localKey]);
                            }

                            catch
                            {
                                // Some log ?
                                skip[localKey] += 1;
                                // thisLine[localKey] = System.DBNull.Value;
                                thisLine[localKey] = null;
                                //thisLine[localKey] = 0.0;
                            }
                        }
                    }

                    // Add to output container
                    outputContainer.Add(thisLine);
                }
            }

            // This kills the data inside the response object...
            this.CloseConnection();

            return(outputContainer);
        }
Example #4
0
        /// <summary>
        /// Processes the Bloomberg subscription data event.
        /// </summary>
        /// <param name="eventObj">The event obj.</param>
        /// <param name="session">The session.</param>
        private void processSubscriptionDataEvent(BB.Event eventObj, BB.Session session)
        {
            try {
                // process message
                foreach (BB.Message msg in eventObj.GetMessages())
                {
                    #region find instrument
                    Guid reqGUID = (Guid)msg.CorrelationID.Object;

                    // check for duplicate replies just in case
                    if (guids.Contains(reqGUID))
                    {
                        return;
                    }
                    else
                    {
                        guids.Add(reqGUID);
                    }

                    // find the correct instrument
                    BloombergDataInstrument bbdi = FindSentInstrumentByGuid(reqGUID);
                    if (bbdi == null)
                    {
                        UpdateStatus("Unable to find received instrument by Guid - " + reqGUID.ToString());
                        continue;
                    }
                    #endregion

                    UpdateStatus(string.Format("Received {0} of {1} requests : {2}", guids.Count, sentToBB.Count, bbdi.Ticker));

                    if (msg.HasElement("responseError"))
                    {
                        BB.Element error         = msg.GetElement(RESPONSE_ERROR);
                        string     responseError = error.GetElementAsString(SUBCATEGORY);
                        UpdateStatus("Response error : " + error.GetElementAsString(MESSAGE));
                        CheckForLimits(responseError);
                        bbdi.HasFieldErrors = true;
                        continue;
                    }
                    BB.Element secDataArray = msg.GetElement(SECURITY_DATA);

                    #region process security data

                    // process security data
                    int numberOfSecurities = secDataArray.NumValues;
                    for (int index = 0; index < numberOfSecurities; index++)
                    {
                        if (msg.MessageType.Equals(Bloomberglp.Blpapi.Name.GetName(BLP_REFERENCE_RESPONSE)))
                        {
                            // just contains the one element, which is actually a sequence
                            BB.Element secData = secDataArray.GetValueAsElement(index);
                            BB.Element fields  = secData.GetElement(FIELD_DATA);

                            GetData(bbdi, fields, secData);
                        }
                        else if (msg.MessageType.Equals(Bloomberglp.Blpapi.Name.GetName(BLP_HISTORICAL_RESPONSE)))
                        {
                            // Historical is handled slightly different.  Can contain many elements each with possibly multiple values
                            foreach (BB.Element secData in secDataArray.Elements)
                            {
                                if (secData.Name != FIELD_DATA)
                                {
                                    continue;
                                }

                                for (int pointIndex = 0; pointIndex < secData.NumValues; pointIndex++)
                                {
                                    BB.Element fields = secData.GetValueAsElement(pointIndex);

                                    GetData(bbdi, fields, secData);
                                }
                            }
                        }
                    }
                    #endregion

                    ShowCompletionPercentage(guids.Count, sentToBB.Count);
                    ShowCompletedInstrument(bbdi);
                }
            } catch (Exception ex) {
                UpdateStatus("Error occurred processing reply : " + ex.Message);
            } finally {
                if (guids.Count == sentToBB.Count)                   // we are done
                {
                    ShowCompletionPercentage(1, 1);
                    ProcessComplete();
                }
            }
        }
Example #5
0
        /// <summary>
        /// Processes misc Bloomberg events.
        /// </summary>
        /// <param name="eventObj">The event obj.</param>
        /// <param name="session">The session.</param>
        private void processMiscEvents(BB.Event eventObj, BB.Session session)
        {
            foreach (BB.Message msg in eventObj.GetMessages())
            {
                UpdateStatus(msg.MessageType.ToString());

                switch (msg.MessageType.ToString())
                {
                case "SessionStarted":
                    break;

                case "SessionTerminated":
                case "SessionStopped":
                    break;

                case "ServiceOpened":
                    break;

                case "RequestFailure":
                    UpdateStatus("*** REQUEST FAILURE ***");

                    BB.Element reason     = msg.GetElement(REASON);
                    string     reasonText = string.Format("Error: Source-[{0}], Code-[{1}], Category-[{2}], Desc-[{3}]",
                                                          reason.GetElementAsString(SOURCE),
                                                          reason.GetElementAsString(ERROR_CODE),
                                                          reason.GetElementAsString(CATEGORY),
                                                          reason.GetElementAsString(DESCRIPTION));
                    UpdateStatus(reasonText);
                    UpdateStatus("Error message body : " + msg.ToString());

                    bool hasGUID          = false;
                    bool hasResponseError = false;
                    try {
                        Guid reqGUID = (Guid)msg.CorrelationID.Object;
                        hasGUID          = true;
                        hasResponseError = msg.HasElement("responseError");
                    } catch {
                        hasGUID          = false;
                        hasResponseError = false;
                    }

                    if (hasGUID & hasResponseError)
                    {
                        UpdateStatus("GUID and responseError found - handling normally");

                        // has both a GUID and a response error so can be handled normally
                        processSubscriptionDataEvent(eventObj, session);
                    }
                    else if (hasGUID)
                    {
                        UpdateStatus("GUID found - updating GUID list.");

                        Guid reqGUID = (Guid)msg.CorrelationID.Object;
                        // only has a GUID so add to the list of returned GUIDs
                        if (!guids.Contains(reqGUID))
                        {
                            guids.Add(reqGUID);
                        }
                    }
                    else
                    {
                        // ok, email out that a timeout has occurred
                        Maple.Email email = new Maple.Email();
                        email.SendEmail(emailErrorsTo,
                                        "Bloomberg Request Failure",
                                        "A RequestFailure response has been returned from Bloomberg." + Environment.NewLine + reasonText + Environment.NewLine + msg.ToString(),
                                        false);
                    }
                    break;

                default:
                    UpdateStatus("*** Unhandled Misc Event ***");
                    break;
                }
            }
        }