//public class IOrdersCallbackHandler : IOrdersCallback //{ // #region IOrdersCallback Members // public void PushUpdates(object msg) // { // if (msg.GetType() == typeof(Rejection)) // { // MessageBox.Show(string.Format("Order: {0} Rejected: {1}", ((Rejection)msg).RequesterOrderID, ((Rejection)msg).RejectionReason)); // } // if (msg.GetType() == typeof(OrderStatusResponse)) // { // OrderStatusResponse status = (OrderStatusResponse)msg; // MessageBox.Show(string.Format("Order: {0} Status: {1} Message: {2}",status.RequesterOrderID, status.OrderStatus.ToString(), status.Message)); // } // else if (msg.GetType() == typeof(string)) // { // MessageBox.Show((msg.ToString())); // } // } // #endregion //} private void button2_Click(object sender, EventArgs e) { if (!isSubscribed) { MessageBox.Show(this, "ya 3am subscribe first!", "Subscription Required", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } try { string result = IsValid(); if (result != "valid") { MessageBox.Show(this, result, "Invalid Order", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (MessageBox.Show(this, "Send Order?", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Cancel) { return; } using (OrdersProxy p = new OrdersProxy()) { //2183732 //p.HandleRequest(new NewSingleOrder() { ClientKey = clientKey, RequesterOrderID = sellRequesterOrderID, OrderType = "Limit", ClientID = 9001, CustodyID = "4508", Price = 35, Quantity = 100, SecurityID = "EGMFC003PX11", OrderSide = "Sell", TimeInForce = "Day" }); //p.HandleRequest(new NewSingleOrder() { ClientKey = clientKey, RequesterOrderID = sellRequesterOrderID, OrderType = "Limit", ClientID = 3001, CustodyID = "4999", Price = 20, Quantity = 10, SecurityID = "EGS48031C016", OrderSide = "Sell", TimeInForce = "Day", DateTime = DateTime.Now, ExchangeID = "CA" }); for (int i = 0; i < nudRepeat.Value; i++) { p.HandleRequest(new NewSingleOrder() { ClientKey = clientKey, RequesterOrderID = Guid.NewGuid(), ClientID = int.Parse(tbClient.Text), CustodyID = tbCust.Text, OrderType = rbLimit.Checked ? "Limit" : "Market", Price = rbLimit.Checked ? double.Parse(tbPrice.Text) : 0, Quantity = int.Parse(tbQty.Text), SecurityID = lblCode.Text.Trim(), OrderSide = "Sell", TimeInForce = tbTIF.Text, DateTime = DateTime.Now, ExchangeID = tbMarket.Text, HandleInst = Contract.Enums.HandleInstruction.No_Broker_Invention }); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void StartRecievingMsgs() { MessageQueue m_msgSenderQueue = new MessageQueue(@".\private$\client"); XmlMessageFormatter formatter = new XmlMessageFormatter(new Type[] { typeof(Fix_OrderAcceptedResponse), typeof(SubscriberInitializationInfo), typeof(AreYouAlive), typeof(SubscriptionStatus), typeof(Fix_OrderRejectionResponse), typeof(Fix_ExecutionReport), typeof(LogOutResponse), typeof(LogOutResponse), typeof(Fix_BusinessMessageReject), typeof(Fix_OrderReplaceCancelReject) }); if (!m_msgSenderQueue.CanRead) { // warning } while (true) { try { //MessageQueueTransaction mqt = new MessageQueueTransaction(); //mqt.Begin(); System.Messaging.Message msg = (System.Messaging.Message)m_msgSenderQueue.Receive(); if (msg == null) { continue; } object recievedMsg = formatter.Read(msg); if (recievedMsg.GetType() == typeof(SubscriptionStatus)) { SubscriptionStatus status = (SubscriptionStatus)recievedMsg; if (status.IsSubscribed) { clientKey = status.ClientKey; this.BeginInvoke(new Action(() => { lblSub.ForeColor = Color.Green; lblSub.Text = "Subscribed"; btnSub.BackColor = Color.Red; btnSub.Text = "Unsubscribe"; isSubscribed = true; btnSub.Enabled = true; } )); } else { this.BeginInvoke(new Action(() => { lblSub.ForeColor = Color.Red; lblSub.Text = "Unsubscribed"; btnSub.BackColor = Color.Green; btnSub.Text = "Subscribe"; isSubscribed = false; btnSub.Enabled = true; } )); //using (OrdersProxy proxy = new OrdersProxy()) //{ // string path = string.Format(@"Formatname:DIRECT=TCP:{0}", SystemConfigurations.GetAppSetting("ResponseQueue")); // proxy.SubscribeSession(path); //} } } else if (recievedMsg.GetType() == typeof(Fix_OrderAcceptedResponse)) { Fix_OrderAcceptedResponse resp = (Fix_OrderAcceptedResponse)recievedMsg; this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} accepted", resp.RequesterOrderID), Color.Green))); } else if (recievedMsg.GetType() == typeof(Fix_ExecutionReport)) { Fix_ExecutionReport resp = (Fix_ExecutionReport)recievedMsg; this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} TotalExecuted: {1}, TradeExecuted: {2}, Remaining {3}, Status : {4}", resp.RequesterOrderID, resp.TotalExecutedQuantity, resp.TradeExecutedQuantity, resp.RemainingQuantity, resp.OrderStatus), Color.Blue))); } else if (recievedMsg.GetType() == typeof(Fix_OrderSuspensionResponse)) { Fix_OrderSuspensionResponse resp = (Fix_OrderSuspensionResponse)recievedMsg; this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} suspended : {1}", resp.RequesterOrderID, resp.Message), Color.Red))); } else if (recievedMsg.GetType() == typeof(Fix_OrderRejectionResponse)) { Fix_OrderRejectionResponse resp = (Fix_OrderRejectionResponse)recievedMsg; this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} rejected : {1}", resp.RequesterOrderID, resp.RejectionReason), Color.Red))); } else if (recievedMsg.GetType() == typeof(AreYouAlive)) { AreYouAlive resp = (AreYouAlive)recievedMsg; //m_msgSenderQueue.Send(new AmAlive() { ClientKey = clientKey }); using (OrdersProxy proxy = new OrdersProxy()) { proxy.HandleRequest(new AmAlive() { ClientKey = clientKey }); } } else if (recievedMsg.GetType() == typeof(Fix_OrderReplacedResponse)) { Fix_OrderReplacedResponse replace = (Fix_OrderReplacedResponse)recievedMsg; this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} replaced : Quantity {1} price {2}", replace.RequesterOrderID, replace.Quantity, replace.Price), Color.DarkOrange))); } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error Sending Msg: " + ex.ToString()); Console.ResetColor(); } } }