コード例 #1
0
ファイル: Trade.cs プロジェクト: d0p34m1n3/repo_barbarossa
        public static bool ChangeLimitOrder(string orderKey, TradingTechnologies.TTAPI.Instrument instrument, Subscription ttapisubs, double price, Logger logger)

        {
            InstrumentTradeSubscription TS = ttapisubs.TsDictionary[instrument.Key];
            bool Status = true;

            OrderProfileBase Op         = TS.Orders[orderKey].GetOrderProfile();
            Price            LimitPrice = Price.FromDouble(instrument.InstrumentDetails, price);

            if (Op.LimitPrice != LimitPrice)
            {
                Op.LimitPrice = LimitPrice;
                Op.Action     = OrderAction.Change;

                if (!TS.SendOrder(Op))
                {
                    logger.Log("Send change order failed.  {0}" + Op.RoutingStatus.Message);
                    Status = false;
                }
                else
                {
                    logger.Log("Send change order succeeded.");
                }
            }

            return(Status);
        }
コード例 #2
0
        /// <summary>
        /// Event notification for price update
        /// </summary>
        void m_ps_FieldsUpdated(object sender, FieldsUpdatedEventArgs e)
        {
            if (e.Error == null)
            {
                // Make sure that there is a valid bid
                if (e.Fields.GetBestBidPriceField().HasValidValue)
                {
                    if (m_orderKey == "")
                    {
                        // If there is no order working, submit one through the first valid order feed.
                        // You should use the order feed that is valid for your purposes.
                        OrderProfile op = new OrderProfile(e.Fields.Instrument.GetValidOrderFeeds()[0], e.Fields.Instrument);
                        op.BuySell       = BuySell.Buy;
                        op.AccountName   = "12345678";
                        op.AccountType   = AccountType.A1;
                        op.OrderQuantity = Quantity.FromInt(e.Fields.Instrument, 10);
                        op.OrderType     = OrderType.Limit;
                        op.LimitPrice    = e.Fields.GetBestBidPriceField().Value;

                        if (!m_ts.SendOrder(op))
                        {
                            Console.WriteLine("Send new order failed.  {0}", op.RoutingStatus.Message);
                            Dispose();
                        }
                        else
                        {
                            m_orderKey = op.SiteOrderKey;
                            Console.WriteLine("Send new order succeeded.");
                        }
                    }
                    else if (m_ts.Orders.ContainsKey(m_orderKey) &&
                             m_ts.Orders[m_orderKey].LimitPrice != e.Fields.GetBestBidPriceField().Value)
                    {
                        // If there is a working order, reprice it if its price is not the same as the bid
                        OrderProfileBase op = m_ts.Orders[m_orderKey].GetOrderProfile();
                        op.LimitPrice = e.Fields.GetBestBidPriceField().Value;
                        op.Action     = OrderAction.Change;

                        if (!m_ts.SendOrder(op))
                        {
                            Console.WriteLine("Send change order failed.  {0}", op.RoutingStatus.Message);
                        }
                        else
                        {
                            Console.WriteLine("Send change order succeeded.");
                        }
                    }
                }
            }
            else
            {
                if (e.Error.IsRecoverableError == false)
                {
                    Console.WriteLine("Unrecoverable price subscription error: {0}", e.Error.Message);
                    Dispose();
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Delete the last order placed by this application.
        /// </summary>
        private void buttonDeleteLast_Click(object sender, EventArgs e)
        {
            // Do we have an order to modify?
            if (m_lastOrder == null)
            {
                MessageBox.Show("No order was found to modify!");
                return;
            }

            // Get the order profile from the previous order.
            OrderProfileBase orderProfile = m_lastOrder.GetOrderProfile();

            // Set the order action to delete.
            orderProfile.Action = OrderAction.Delete;

            // Send the delete.
            m_instrumentTradeSubscription.SendOrder(orderProfile);
        }
コード例 #4
0
ファイル: Trade.cs プロジェクト: d0p34m1n3/repo_barbarossa
        public static bool CancelLimitOrder(string orderKey, TradingTechnologies.TTAPI.Instrument instrument, Subscription ttapisubs, Logger logger)
        {
            InstrumentTradeSubscription TS = ttapisubs.TsDictionary[instrument.Key];
            bool Status = true;

            OrderProfileBase Op = TS.Orders[orderKey].GetOrderProfile();

            Op.Action = OrderAction.Delete;

            if (!TS.SendOrder(Op))
            {
                logger.Log("Cancal order failed.  {0}" + Op.RoutingStatus.Message);
                Status = false;
            }
            else
            {
                logger.Log("Cancel order succeeded.");
            }

            return(Status);
        }
コード例 #5
0
        /// <summary>
        /// This function is called when the Invoke button in the
        /// Delete Order group is clicked.  Three ways of deleting
        /// orders are demonstrated.
        /// </summary>
        /// <param name="sender">Object which fires the method</param>
        /// <param name="e">Event arguments of the callback</param>
        private void btnInvokeModify_Click(object sender, EventArgs e)
        {
            bool didChange = false;

            // Do we have an order to modify?
            if (m_lastOrder == null)
            {
                MessageBox.Show("No order was found to modify!");
                return;
            }

            // Get the order profile from the previous order.
            OrderProfileBase orderProfile = m_lastOrder.GetOrderProfile();

            // Update Order as change or cancel/replace.
            orderProfile.Action = cboModifyType.SelectedIndex <= 0 ? OrderAction.Change : OrderAction.Replace;

            // Set the new price.
            if (!String.IsNullOrEmpty(txtNewPrice.Text))
            {
                orderProfile.LimitPrice = Price.FromString(m_lastOrder, txtNewPrice.Text);
                didChange = true;
            }

            // Set the new quantity.
            if (!String.IsNullOrEmpty(txtNewQuantity.Text))
            {
                orderProfile.QuantityToWork = Quantity.FromString(m_lastOrder, txtNewQuantity.Text);
                didChange = true;
            }

            // If there was a change then send the order.
            if (didChange)
            {
                m_instrumentTradeSubscription.SendOrder(orderProfile);
            }
        }