예제 #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);
        }
예제 #2
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);
        }