コード例 #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            //Sell Modfiy
            try
            {
                using (OrdersProxy p = new OrdersProxy())
                {
                    //Dictionary<string, object> optionalParams = new Dictionary<string, object>();
                    //optionalParams.Add("ALLOC_TYPE", ALLOC_TYPE.REGULAR);
                    //optionalParams.Add("UnifiedCode", "2079333");

                    Guid reqGuid = new Guid(tbRequestGuid.Text);


                    p.Handle(new ModifyCancelOrder()
                    {
                        ClientKey = clientKey, OrderType = "Limit", Price = double.Parse(tbPrice.Text), Quantity = int.Parse(tbQty.Text), RequesterOrderID = reqGuid, TimeInForce = "Day", OptionalParam = null
                    });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        private void btnSub_Click(object sender, EventArgs e)
        {
            //if (MessageBox.Show(this, "Subscribe to FIX orders service ?", "FIX Service", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
            {
                using (OrdersProxy proxy = new OrdersProxy())
                {
                    //string path = string.Format(@"{0}\private$\client", Environment.MachineName);
                    //string path = @"10.30.60.11\private$\client";
                    //string ip = SystemConfigurations.GetMachineIP();

                    btnSub.Enabled = false;

                    if (!isSubscribed)
                    {
                        string path = string.Format(@"Formatname:DIRECT=TCP:{0}", SystemConfigurations.GetAppSetting("ResponseQueue"));
                        proxy.SubscribeSession(path);
                    }
                    else
                    {
                        proxy.UnsubscribeSession(clientKey);
                    }
                    //66A92E99-721E-47C2-B866-FA853E0AE17F
                    //proxy.ResubscribeMe(new Guid("57D42C89-2EF5-4AEA-9C67-8CE0F0A8088C"), @".\private$\client");
                }
            }
        }
コード例 #3
0
        private void btnSub_Click(object sender, EventArgs e)
        {
            //if (MessageBox.Show(this, "Subscribe to FIX orders service ?", "FIX Service", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
            {
                using (OrdersProxy proxy = new OrdersProxy())
                {
                    btnSub.Enabled = false;

                    ICallbackHandler m_callbackHandler;
                    InstanceContext  m_InstanceContext;
                    DuplexChannelFactory <IFixAdmin>         m_factory;
                    ICallbackHandler.IncomingMessageDelegate m_IncomingMessageDelegate = new ICallbackHandler.IncomingMessageDelegate(OnIncomingMsg);
                    m_callbackHandler = new ICallbackHandler(m_IncomingMessageDelegate);
                    m_InstanceContext = new InstanceContext(m_callbackHandler);
                    m_factory         = new DuplexChannelFactory <IFixAdmin>(m_InstanceContext, "netTcpBinding_IFixAdmin");
                    _client           = m_factory.CreateChannel();
                    ((ICommunicationObject)_client).Closed  += TcpClient_Closed;
                    ((ICommunicationObject)_client).Faulted += tcpClient_Faulted;
                    //for (int i = 0; i < 3; i++)
                    //{
                    try
                    {
                        FixAdminMsg returnMsg = _client.Subscribe(
                            new subReq()
                        {
                            Username            = "******",
                            Password            = "******",
                            QueueName           = SystemConfigurations.GetAppSetting("ResponseQueueName"),
                            QueueIP             = SystemConfigurations.GetAppSetting("ResponseQueueIP"),
                            FlushUpdatesOffline = true,
                        });

                        //FixAdminMsg returnMsg = _client.Resubscribe(
                        //   new ResupReq()
                        //   {
                        //       SessionKey = new Guid("6D0AC300-CC63-4F34-81B6-B4E6DB358DC6"),
                        //       NewQueue = true,
                        //       QueueName = SystemConfigurations.GetAppSetting("ResponseQueueName"),
                        //       QueueIP = SystemConfigurations.GetAppSetting("ResponseQueueIP"),
                        //       Username = "******",
                        //       Password = "******",
                        //       FlushUpdatesOffline = true,
                        //   });

                        isConnectedToAdmin = true;
                        SetReport(returnMsg.Code + " " + returnMsg.Note ?? "");
                        //   Task.Factory.StartNew(() => { while (isConnectedToAdmin) { _client.Ping(); Thread.Sleep(3000); } }, tokenSource.Token);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    //}
                }
            }
        }
コード例 #4
0
        private void button1_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())
                {//EGMFC003PX11
                    //p.HandleRequest(new NewSingleOrder() { ClientKey = clientKey, RequesterOrderID = buyRequesterOrderID, ClientID = 1001, CustodyID = "4508", OrderType = "Limit", Price = 18, Quantity = 100, SecurityID = "EGS48031C016", OrderSide = "Buy", TimeInForce = "Day", CurrencyCode = "EGP", DateTime = DateTime.Now, ExchangeID = "CA" });
                    //p.HandleRequest(new NewSingleOrder() { ClientKey = clientKey, RequesterOrderID = buyRequesterOrderID, ClientID = 3001, CustodyID = "4999", OrderType = "Limit", Price = 20, Quantity = 10, SecurityID = "EGS48031C016", OrderSide = "Buy", TimeInForce = "Day", DateTime = DateTime.Now, ExchangeID = "CA", HandleInst = Contract.Enums.HandleInstruction.No_Broker_Invention });
                    for (int i = 0; i < nudRepeat.Value; i++)
                    {
                        Dictionary <string, object> optionalParams = new Dictionary <string, object>();
                        //optionalParams.Add("ALLOC_TYPE", ALLOC_TYPE.REGULAR);
                        //optionalParams.Add("UnifiedCode", "2079333");
                        Guid reqGuid = Guid.NewGuid();
                        tbRequestGuid.Text = reqGuid.ToString();
                        p.Handle(new NewSingleOrder()
                        {
                            ClientKey = clientKey, RequesterOrderID = reqGuid, 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 = "Buy", TimeInForce = combTimeInforce.Text.Trim(), DateTime = DateTime.Now, ExchangeID = tbMarket.Text, HandleInst = Contract.Enums.HandleInstruction.No_Broker_Invention, ExpirationDateTime = DateTime.Now.AddDays(3), OptionalParam = optionalParams
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #5
0
        //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);
            }
        }
コード例 #6
0
        private void btnCancelBuy_Click(object sender, EventArgs e)
        {
            try
            {
                using (OrdersProxy p = new OrdersProxy())
                {
                    Dictionary <string, object> optionalParams = new Dictionary <string, object>();
                    //optionalParams.Add("ALLOC_TYPE", ALLOC_TYPE.REGULAR);
                    //optionalParams.Add("UnifiedCode", "2079333");

                    Guid reqGuid = new Guid(tbRequestGuid.Text);

                    p.Handle(new CancelSingleOrder()
                    {
                        ClientKey = clientKey, OptionalParam = optionalParams, RequesterOrderID = reqGuid
                    });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #7
0
        private void PlaceSellOrderWithAllocation()
        {
            using (OrdersProxy p = new OrdersProxy())
            {
                Guid reqGuid = Guid.NewGuid();  // request orderid created by client.

                Dictionary <string, object> optionalParams = new Dictionary <string, object>();

                string allocType = comboBoxAllocationType.SelectedItem.ToString();

                optionalParams.Add("ALLOC_TYPE", ALLOC_TYPE.REGULAR); // to allocate t+2
                // or   // optionalParams.Add("ALLOC_TYPE", ALLOC_TYPE.SAMEDAY); // to allocate t+0
                // or //  optionalParams.Add("ALLOC_TYPE", ALLOC_TYPE.SAMEDAYPLUS); // to allocate same day plus.
                // client UnifiedCode is mandatory.
                optionalParams.Add("UnifiedCode", txtUnifiedCode.Text.Trim());

                p.Handle(new NewSingleOrder()
                {
                    ClientKey          = clientKey,                // session Guid key
                    RequesterOrderID   = reqGuid,                  // unique orderid GUID
                    ClientID           = int.Parse(tbClient.Text), // Bimsi ClientID
                    CustodyID          = "4603",
                    OrderType          = "Limit",                  // or "Market"
                    Price              = 212.5,
                    Quantity           = 100,
                    SecurityID         = "EGB48011G026",
                    OrderSide          = "Sell",
                    TimeInForce        = "Day",
                    DateTime           = DateTime.Now,
                    ExchangeID         = "CA",
                    HandleInst         = Contract.Enums.HandleInstruction.No_Broker_Invention,
                    ExpirationDateTime = DateTime.Now,  // order expiry dayte
                    OptionalParam      = optionalParams
                });
            }
        }
コード例 #8
0
        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();
                }
            }
        }
コード例 #9
0
        //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++)
                    {
                        Guid reqGuid = Guid.NewGuid();
                        tbRequestGuid.Text = reqGuid.ToString();


                        Dictionary <string, object> optionalParams = new Dictionary <string, object>();



                        string allocType = comboBoxAllocationType.SelectedItem.ToString();

                        switch (allocType)
                        {
                        case "Regular":
                            optionalParams.Add("ALLOC_TYPE", ALLOC_TYPE.REGULAR);
                            break;

                        case "SameDay":
                            optionalParams.Add("ALLOC_TYPE", ALLOC_TYPE.SAMEDAY);
                            break;

                        case "SameDay_Plus":
                            optionalParams.Add("ALLOC_TYPE", ALLOC_TYPE.SAMEDAYPLUS);
                            break;

                        default:
                            break;
                        }

                        optionalParams.Add("UnifiedCode", txtUnifiedCode.Text.Trim());

                        p.Handle(new NewSingleOrder()
                        {
                            ClientKey = clientKey, RequesterOrderID = reqGuid, 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 = combTimeInforce.Text.Trim(), DateTime = DateTime.Now, ExchangeID = tbMarket.Text, HandleInst = Contract.Enums.HandleInstruction.No_Broker_Invention, OptionalParam = optionalParams
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }