private void processMessage(Message msg) { Element data = msg.GetElement(BAR_DATA).GetElement(BAR_TICK_DATA); int numBars = data.NumValues; System.Console.WriteLine("Response contains " + numBars + " bars"); System.Console.WriteLine("Datetime\t\tOpen\t\tHigh\t\tLow\t\tClose" + "\t\tNumEvents\tVolume"); for (int i = 0; i < numBars; ++i) { Element bar = data.GetValueAsElement(i); Datetime time = bar.GetElementAsDate(TIME); double open = bar.GetElementAsFloat64(OPEN); double high = bar.GetElementAsFloat64(HIGH); double low = bar.GetElementAsFloat64(LOW); double close = bar.GetElementAsFloat64(CLOSE); int numEvents = bar.GetElementAsInt32(NUM_EVENTS); long volume = bar.GetElementAsInt64(VOLUME); System.DateTime sysDatetime = time.ToSystemDateTime(); System.Console.WriteLine( sysDatetime.ToString("s") + "\t" + open.ToString("C") + "\t\t" + high.ToString("C") + "\t\t" + low.ToString("C") + "\t\t" + close.ToString("C") + "\t\t" + numEvents + "\t\t" + volume); } }
private void processMessage(Message msg) { Element data = msg.GetElement(TICK_DATA).GetElement(TICK_DATA);; int numItems = data.NumValues; System.Console.WriteLine("TIME\t\t\tTYPE\tVALUE\t\tSIZE\tCC"); System.Console.WriteLine("----\t\t\t----\t-----\t\t----\t--"); for (int i = 0; i < numItems; ++i) { Element item = data.GetValueAsElement(i); Datetime time = item.GetElementAsDate(TIME); string type = item.GetElementAsString(TYPE); double value = item.GetElementAsFloat64(VALUE); int size = item.GetElementAsInt32(SIZE); string cc = ""; if (item.HasElement(COND_CODE)) { cc = item.GetElementAsString(COND_CODE); } System.DateTime sysDatetime = new System.DateTime(time.Year, time.Month, time.DayOfMonth, time.Hour, time.Minute, time.Second, time.MilliSecond); System.Console.WriteLine( sysDatetime.ToString("s") + "\t" + type + "\t" + value.ToString("C") + "\t\t" + size + "\t" + cc); } }
void ProcessFields(Message msg) { String delimiter = "\t"; //Print out the date column header System.Console.Write("DATE" + delimiter + delimiter); // Print out the field column headers for (int k = 0; k < d_fields.Count; k++) { System.Console.Write(d_fields[k].ToString() + delimiter); } System.Console.Write("\n\n"); Element securityData = msg.GetElement(SECURITY_DATA); Element fieldData = securityData.GetElement(FIELD_DATA); //Iterate through all field values returned in the message if (fieldData.NumValues > 0) { for (int j = 0; j < fieldData.NumValues; j++) { Element element = fieldData.GetValueAsElement(j); //Print out the date Datetime date = element.GetElementAsDatetime(DATE); System.Console.Write(date.DayOfMonth + "/" + date.Month + "/" + date.Year + delimiter); //Check for the presence of all the fields requested for (int k = 0; k < d_fields.Count; k++) { String temp_field_str = d_fields[k].ToString(); if (element.HasElement(temp_field_str)) { Element temp_field = element.GetElement(temp_field_str); Name TEMP_FIELD_STR = new Name(temp_field_str); int datatype = temp_field.Datatype.GetHashCode(); //Extract the value dependent on the dataype and print to the console switch (datatype) { case (int)DataType.BOOL: //Bool { bool field1; field1 = element.GetElementAsBool(TEMP_FIELD_STR); System.Console.Write(field1 + delimiter); break; } case (int)DataType.CHAR: //Char { char field1; field1 = element.GetElementAsChar(TEMP_FIELD_STR); System.Console.Write(field1 + delimiter); break; } case (int)DataType.INT32: //Int32 { Int32 field1; field1 = element.GetElementAsInt32(TEMP_FIELD_STR); System.Console.Write(field1 + delimiter); break; } case (int)DataType.INT64: //Int64 { Int64 field1; field1 = element.GetElementAsInt64(TEMP_FIELD_STR); System.Console.Write(field1 + delimiter); break; } case (int)DataType.FLOAT32: //Float32 { float field1; field1 = element.GetElementAsFloat32(TEMP_FIELD_STR); System.Console.Write(field1 + delimiter); break; } case (int)DataType.FLOAT64: //Float64 { double field1; field1 = element.GetElementAsFloat64(TEMP_FIELD_STR); System.Console.Write(field1 + delimiter); break; } case (int)DataType.STRING: //String { String field1; field1 = element.GetElementAsString(TEMP_FIELD_STR); System.Console.Write(field1 + delimiter); break; } case (int)DataType.DATE: //Date { Datetime field1; field1 = element.GetElementAsDatetime(TEMP_FIELD_STR); System.Console.Write(field1.Year + '/' + field1.Month + '/' + field1.DayOfMonth + delimiter); break; } case (int)DataType.TIME: //Time { Datetime field1; field1 = element.GetElementAsDatetime(TEMP_FIELD_STR); System.Console.Write(field1.Hour + '/' + field1.Minute + '/' + field1.Second + delimiter); break; } case (int)DataType.DATETIME: //Datetime { Datetime field1; field1 = element.GetElementAsDatetime(TEMP_FIELD_STR); System.Console.Write(field1.Year + '/' + field1.Month + '/' + field1.DayOfMonth + '/'); System.Console.Write(field1.Hour + '/' + field1.Minute + '/' + field1.Second + delimiter); break; } default: { String field1; field1 = element.GetElementAsString(TEMP_FIELD_STR); System.Console.Write(field1 + delimiter); break; } } //end of switch } //end of if System.Console.WriteLine(""); } //end of for } //end of for } //end of if } //end of method