Esempio n. 1
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 == "")
                    {
                        // In this example, the order is submitted to ASE-A.
                        // You should use the order feed that is appropriate for your purposes.
                        AutospreaderSyntheticOrderProfile op = new AutospreaderSyntheticOrderProfile(((AutospreaderInstrument)e.Fields.Instrument).GetValidGateways()[m_ASEGateway],
                                                                                                     (AutospreaderInstrument)e.Fields.Instrument);
                        op.BuySell       = BuySell.Buy;
                        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);
                        }
                        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
                        AutospreaderSyntheticOrderProfile op = m_ts.Orders[m_orderKey].GetOrderProfile() as AutospreaderSyntheticOrderProfile;
                        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();
                }
            }
        }
Esempio n. 2
0
        public static string SendAutospreaderOrder(ttapiUtils.AutoSpreader autoSpreader,
                                                   int qty, decimal price, string orderTag, Logger logger, int reloadQuantity = 0)

        {
            Instrument        instrument        = autoSpreader.AutoSpreaderInstrument;
            InstrumentDetails instrumentDetails = instrument.InstrumentDetails;

            AutospreaderSyntheticOrderProfile op = new AutospreaderSyntheticOrderProfile(((AutospreaderInstrument)instrument).GetValidGateways()[autoSpreader.GateWay],
                                                                                         (AutospreaderInstrument)instrument);

            BuySell  Direction = BuySell.Buy;
            Rounding Rounding  = Rounding.Down;

            if (qty < 0)
            {
                Direction = BuySell.Sell;
                qty       = -qty;
                Rounding  = Rounding.Up;
            }

            string OrderKey = op.SiteOrderKey;

            if (reloadQuantity != 0)
            {
                op.SlicerType        = SlicerType.Reload;
                op.DisclosedQuantity = Quantity.FromInt(instrument, reloadQuantity);
            }

            op.BuySell       = Direction;
            op.OrderQuantity = Quantity.FromInt(instrument, qty);
            op.OrderType     = OrderType.Limit;
            op.OrderTag      = orderTag;
            op.LimitPrice    = Price.FromDouble(instrumentDetails, Convert.ToDouble(price), Rounding);

            if (!autoSpreader.ts.SendOrder(op))
            {
                logger.Log("Send new order failed: " + op.RoutingStatus.Message);
            }
            else
            {
                logger.Log("Send new order succeeded.");
            }

            return(OrderKey);
        }
Esempio n. 3
0
        private void SendLimitOrder(BuySell buySell, int qty, double price)
        {
            OrderFeed        feed = GetOrderFeed();
            LaunchReturnCode lrc  = SpreadInstrument.LaunchToOrderFeed(feed);

            if (lrc == LaunchReturnCode.Success)
            {
                AutospreaderSyntheticOrderProfile prof = new AutospreaderSyntheticOrderProfile(feed, SpreadInstrument);
                prof.BuySell       = buySell;
                prof.OrderQuantity = Quantity.FromInt(SpreadInstrument, qty);
                prof.OrderType     = OrderType.Limit;
                prof.LimitPrice    = Price.FromDouble(SpreadInstrument, price);

                if (!SpreadInstrument.Session.SendOrder(prof))
                {
                    Console.WriteLine("send order failed: {0}", prof.RoutingStatus.Message);
                }
            }
        }
Esempio n. 4
0
        public static bool SendAutospreaderOrder(TradingTechnologies.TTAPI.Instrument instrument, InstrumentDetails instrumentDetails, ttapiUtils.AutoSpreader autoSpreader, 
            int qty, decimal price, string orderTag,Logger logger)
        {
            AutospreaderSyntheticOrderProfile op = new AutospreaderSyntheticOrderProfile(((AutospreaderInstrument)instrument).GetValidGateways()[autoSpreader.GateWay],
                            (AutospreaderInstrument)instrument);

            BuySell Direction = BuySell.Buy;
            Rounding Rounding = Rounding.Down;

            if (qty < 0)
            {
                Direction = BuySell.Sell;
                qty = -qty;
                Rounding = Rounding.Up;
            }


            op.BuySell = Direction;
            op.OrderQuantity = Quantity.FromInt(instrument, qty);
            op.OrderType = OrderType.Limit;
            op.OrderTag = orderTag;
            op.LimitPrice = Price.FromDouble(instrumentDetails, Convert.ToDouble(price), Rounding);

            if (!autoSpreader.ts.SendOrder(op))
            {
                logger.Log("Send new order failed: " +  op.RoutingStatus.Message);
                return false;
                
            }
            else
            {
                logger.Log("Send new order succeeded.");
                return true;
            }

        }
Esempio n. 5
0
        public static bool CancelAutospreaderOrder(string orderKey, ttapiUtils.AutoSpreader autoSpreader, Logger logger)
        {
            ASInstrumentTradeSubscription Ts = autoSpreader.ts;
            bool Status = false;

            if (Ts.Orders.ContainsKey(orderKey))
            {
                AutospreaderSyntheticOrderProfile Op = Ts.Orders[orderKey].GetOrderProfile() as AutospreaderSyntheticOrderProfile;

                Op.Action = OrderAction.Delete;

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

            return(Status);
        }
Esempio n. 6
0
        public static bool ChangeAutospreaderOrder(string orderKey, decimal price, ttapiUtils.AutoSpreader autoSpreader,
                                                   TradingTechnologies.TTAPI.Instrument instrument, Logger logger)
        {
            ASInstrumentTradeSubscription Ts = autoSpreader.ts;
            bool Status = false;

            if (Ts.Orders.ContainsKey(orderKey))
            {
                AutospreaderSyntheticOrderProfile Op = Ts.Orders[orderKey].GetOrderProfile() as AutospreaderSyntheticOrderProfile;
                Rounding Rounding = Rounding.Down;

                if (Op.BuySell == BuySell.Sell)
                {
                    Rounding = Rounding.Up;
                }

                Price LimitPrice = Price.FromDouble(instrument.InstrumentDetails, Convert.ToDouble(price), Rounding);

                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);
                    }
                    else
                    {
                        logger.Log("Send change order succeeded.");
                        Status = true;
                    }
                }
            }
            return(Status);
        }
        /// <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 == "")
                    {
                        // In this example, the order is submitted to ASE-A.
                        // You should use the order feed that is appropriate for your purposes.
                        AutospreaderSyntheticOrderProfile op = new AutospreaderSyntheticOrderProfile(((AutospreaderInstrument)e.Fields.Instrument).GetValidGateways()[m_ASEGateway], 
                            (AutospreaderInstrument)e.Fields.Instrument);
                        op.BuySell = BuySell.Buy;
                        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);
                        }
                        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
                        AutospreaderSyntheticOrderProfile op = m_ts.Orders[m_orderKey].GetOrderProfile() as AutospreaderSyntheticOrderProfile;
                        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();
                }
            }
        }
        private void StartOrderSubmission(AutospreaderInstrument instrument)
        {
            // Submit an Autospreader order to the local Autospreader Engine.  As a result, the
            // Autospreader Instrument need not be launched to it.  If you are going to use any other
            // Autospreader Engine, you will need to launch the Autospreader Instrument to it.
            Console.WriteLine("Submitting the Autospreader order to the local Autospreader Engine...");

            // An ASInstrumentTradeSubscription object is filtered by the given Autospreader instrument
            ts = new ASInstrumentTradeSubscription(apiInstance.Session, Dispatcher.Current, instrument);

            ts.OrderAdded += new EventHandler<OrderAddedEventArgs>(ts_OrderAdded);
            ts.OrderFilled += new EventHandler<OrderFilledEventArgs>(ts_OrderFilled);
            ts.OrderRejected += new EventHandler<OrderRejectedEventArgs>(ts_OrderRejected);
            ts.OrderDeleted += new EventHandler<OrderDeletedEventArgs>(ts_OrderDeleted);
            ts.OrderUpdated += new EventHandler<OrderUpdatedEventArgs>(ts_OrderUpdated);
            ts.Start();

            AutospreaderSyntheticOrderProfile profile = new AutospreaderSyntheticOrderProfile(
                apiInstance.Session.MarketCatalog.LocalAutospreaderEngineOrderFeed, instrument);
            profile.QuantityToWork = Quantity.FromInt(instrument, 1);
            profile.OrderType = OrderType.Limit;
            profile.BuySell = BuySell.Buy;
            profile.LimitPrice = Price.FromInt(instrument, 0);

            if (apiInstance.Session.SendOrder(profile))
            {
                orderKey = profile.SiteOrderKey;
                Console.WriteLine("Order Submitted, key: {0}", profile.SiteOrderKey);
            }
            else
            {
                Console.WriteLine("Send Order failed: {0}", profile.RoutingStatus.Message);
                Dispose();
            }
        }