public void PrintMessage(Message message) { // tbMessages.AppendText(message.Text + "\n"); }
private void OnTick(object sender, EventArgs e) { // tbMarketData.AppendText("."); //1. Check Messages if (!messageBox.IsEmpty) { for (int i = 0; i < messageBox.Count; i++) { var outMessage = new Message(); messageBox.TryDequeue(out outMessage); switch (outMessage.MessageType) { case SPXWPFTrader.MessageType.GeneralNotification: Message msg1 = (Message)outMessage; // MyMainWindow.tbMessages.AppendText(msg1.Text+"\n"); UpdateMessageBox(msg1.Text); break; case SPXWPFTrader.MessageType.Error: break; case SPXWPFTrader.MessageType.PriceTick: TickPriceMessage tpMessage = (TickPriceMessage)outMessage; InstrumentManager.ProcessPriceTick(tpMessage.ReqId, tpMessage.Field, tpMessage.Price, tpMessage.CanExecute); UpdateDataBox("PriceTick:\t"+tpMessage.ReqId + "\t" + TickType.getField(tpMessage.Field) + "\t" + tpMessage.Price); break; case MessageType.TickSize: TickSizeMessage tsMessage = (TickSizeMessage)outMessage; InstrumentManager.ProcessPriceSize(tsMessage.ReqId, tsMessage.Field, tsMessage.Size); UpdateDataBox("TickSize:\t" + tsMessage.ReqId + "\t" + TickType.getField(tsMessage.Field) + "\t" + tsMessage.Size); break; case MessageType.TickString: TickStringMessage tstMessage = (TickStringMessage)outMessage; InstrumentManager.ProcessPriceString(tstMessage.ReqId, tstMessage.Field, tstMessage.Value); var field = tstMessage.Field; if (field == 45) { var value = Convert.ToInt32(tstMessage.Value); lastUpdate = epochTime.AddSeconds(value).ToLocalTime(); } var age = (DateTime.Now - lastUpdate).Seconds; UpdateDataBox("TickString:\t" + tstMessage.ReqId + "\t" + TickType.getField(tstMessage.Field) + "\tAge:"+age+"\tUpdate:" +lastUpdate); break; case MessageType.TickGeneric: TickGenericMessage tgMessage = (TickGenericMessage)outMessage; //Using same pricess Method InstrumentManager.ProcessTickGeneric(tgMessage.ReqId, tgMessage.Field, tgMessage.Value); UpdateDataBox("TickGeneric:\t" + tgMessage.ReqId + "\t" + TickType.getField(tgMessage.Field) + "\t" + tgMessage.Value); break; case SPXWPFTrader.MessageType.OpenOrder: OpenOrderMessage ooMessage = (OpenOrderMessage)outMessage; OrderManager.UpdateOrder(ooMessage); MyMainWindow.UpdateTables(); break; case SPXWPFTrader.MessageType.OrderStatus: break; case SPXWPFTrader.MessageType.ContractDetails: ContractDetailsMesage cdMesage = (ContractDetailsMesage)outMessage; InstrumentManager.ProcessContractDetails(cdMesage.RequestId, cdMesage.ContractDetails); var cd = cdMesage.ContractDetails; UpdateMessageBox( "\n" + "Name:\t" + cd.LongName + "\nSymbol:\t" + cd.Summary.LocalSymbol + "\n" + "Month:\t" + cd.ContractMonth + "\nLiquid Hours:\t" + cd.TradingHours + "\nOrderTypes:\t+" + cd.OrderTypes + "\nSummary:\t" + cd.Summary); MyMainWindow.UpdateTables(); break; case SPXWPFTrader.MessageType.ExecutionDetails: ExecutionMessage exMesage = (ExecutionMessage)outMessage; OrderManager.UpdateExecution(exMesage); MyMainWindow.UpdateTables(); break; case SPXWPFTrader.MessageType.CommisionData: break; case SPXWPFTrader.MessageType.PositionReport: break; default: throw new ArgumentOutOfRangeException(); } } } //2. Ping IB Connection //if (EwarapperImpl.IsConnected) //{ // EwarapperImpl.ClientSocket.IsConnected(); //} }