Пример #1
0
        /// <summary>
        /// Event notification for AutospreaderInstrument launch
        /// </summary>
        void Instrument_TradableStatusChanged(object sender, TradableStatusChangedEventArgs e)
        {
            if (e.Value)
            {
                // launch of AutospreaderInstrument was successful
                AutospreaderInstrument instr = sender as AutospreaderInstrument;

                // Subscribe for Inside Market Data
                m_ps                = new PriceSubscription(instr, Dispatcher.Current);
                m_ps.Settings       = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
                m_ps.FieldsUpdated += new FieldsUpdatedEventHandler(m_ps_FieldsUpdated);
                m_ps.Start();

                // Create an ASTradeSubscription to listen for order / fill events only for orders submitted through it
                m_ts = new ASInstrumentTradeSubscription(m_apiInstance.Session, Dispatcher.Current, instr, true, true, false, false);
                m_ts.OrderUpdated  += new EventHandler <OrderUpdatedEventArgs>(m_ts_OrderUpdated);
                m_ts.OrderAdded    += new EventHandler <OrderAddedEventArgs>(m_ts_OrderAdded);
                m_ts.OrderDeleted  += new EventHandler <OrderDeletedEventArgs>(m_ts_OrderDeleted);
                m_ts.OrderFilled   += new EventHandler <OrderFilledEventArgs>(m_ts_OrderFilled);
                m_ts.OrderRejected += new EventHandler <OrderRejectedEventArgs>(m_ts_OrderRejected);
                m_ts.Start();
            }
            else
            {
                Console.WriteLine("Launch of AutospreaderInstrument to {0} was unsuccessful.", e.OrderFeed.Name);
            }
        }
Пример #2
0
        /// <summary>
        /// Shuts down the TT API
        /// </summary>
        public void Dispose()
        {
            lock (m_lock)
            {
                if (!m_disposed)
                {
                    // Unattached callbacks and dispose of all subscriptions
                    if (m_req1 != null)
                    {
                        m_req1.Update -= m_req_Update;
                        m_req1.Dispose();
                        m_req1 = null;
                    }
                    if (m_req2 != null)
                    {
                        m_req2.Update -= m_req_Update;
                        m_req2.Dispose();
                        m_req2 = null;
                    }
                    if (m_ps != null)
                    {
                        m_ps.FieldsUpdated -= m_ps_FieldsUpdated;
                        m_ps.Dispose();
                        m_ps = null;
                    }
                    if (m_ts != null)
                    {
                        m_ts.OrderAdded    -= m_ts_OrderAdded;
                        m_ts.OrderDeleted  -= m_ts_OrderDeleted;
                        m_ts.OrderFilled   -= m_ts_OrderFilled;
                        m_ts.OrderRejected -= m_ts_OrderRejected;
                        m_ts.OrderUpdated  -= m_ts_OrderUpdated;
                        m_ts.Dispose();
                        m_ts = null;
                    }
                    if (m_casReq != null)
                    {
                        m_casReq.Completed -= m_casReq_Completed;
                        m_casReq.Dispose();
                        m_casReq = null;
                    }

                    // Begin shutdown the TT API
                    TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted);
                    TTAPI.Shutdown();

                    m_disposed = true;
                }
            }
        }
Пример #3
0
        TTSpread processSpreadFound(Instrument instrument)
        {
            PriceSubscription priceSub = new PriceSubscription(instrument, Dispatcher.Current);

            priceSub.Settings       = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
            priceSub.FieldsUpdated += new FieldsUpdatedEventHandler(priceSub_FieldsUpdated);
            priceSub.Start();

            ASInstrumentTradeSubscription its = new ASInstrumentTradeSubscription(_apiSession, Dispatcher.Current, instrument as AutospreaderInstrument);

            its.EnablePNL          = true;
            its.ProfitLossChanged += new EventHandler <ProfitLossChangedEventArgs>(its_ProfitLossChanged);
            its.Start();

            TTSpread tts = NewTTSpread(instrument);

            tts.TradeSubscription = its;

            tts.OrderRoute = OrderRoute.GetOrderRoute(tts, instrument.Product.Market.Name);

            return(tts);
        }
Пример #4
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);
        }
Пример #5
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>
        /// Shuts down the TT API
        /// </summary>
        public void Dispose()
        {
            lock (m_lock)
            {
                if (!m_disposed)
                {
                    // Unattached callbacks and dispose of all subscriptions
                    if (m_req1 != null)
                    {
                        m_req1.Update -= m_req_Update;
                        m_req1.Dispose();
                        m_req1 = null;
                    }
                    if (m_req2 != null)
                    {
                        m_req2.Update -= m_req_Update;
                        m_req2.Dispose();
                        m_req2 = null;
                    }
                    if (m_ps != null)
                    {
                        m_ps.FieldsUpdated -= m_ps_FieldsUpdated;
                        m_ps.Dispose();
                        m_ps = null;
                    }
                    if (m_ts != null)
                    {
                        m_ts.OrderAdded -= m_ts_OrderAdded;
                        m_ts.OrderDeleted -= m_ts_OrderDeleted;
                        m_ts.OrderFilled -= m_ts_OrderFilled;
                        m_ts.OrderRejected -= m_ts_OrderRejected;
                        m_ts.OrderUpdated -= m_ts_OrderUpdated;
                        m_ts.Dispose();
                        m_ts = null;
                    }
                    if (m_casReq != null)
                    {
                        m_casReq.Completed -= m_casReq_Completed;
                        m_casReq.Dispose();
                        m_casReq = null;
                    }

                    // Begin shutdown the TT API
                    TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted);
                    TTAPI.Shutdown();

                    m_disposed = true;
                }
            }
        }
        /// <summary>
        /// Event notification for AutospreaderInstrument launch
        /// </summary>
        void Instrument_TradableStatusChanged(object sender, TradableStatusChangedEventArgs e)
        {
            if (e.Value)
            {
                // launch of AutospreaderInstrument was successful
                AutospreaderInstrument instr = sender as AutospreaderInstrument;

                // Subscribe for Inside Market Data
                m_ps = new PriceSubscription(instr, Dispatcher.Current);
                m_ps.Settings = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
                m_ps.FieldsUpdated += new FieldsUpdatedEventHandler(m_ps_FieldsUpdated);
                m_ps.Start();

                // Create an ASTradeSubscription to listen for order / fill events only for orders submitted through it
                m_ts = new ASInstrumentTradeSubscription(m_apiInstance.Session, Dispatcher.Current, instr, true, true, false, false);
                m_ts.OrderUpdated += new EventHandler<OrderUpdatedEventArgs>(m_ts_OrderUpdated);
                m_ts.OrderAdded += new EventHandler<OrderAddedEventArgs>(m_ts_OrderAdded);
                m_ts.OrderDeleted += new EventHandler<OrderDeletedEventArgs>(m_ts_OrderDeleted);
                m_ts.OrderFilled += new EventHandler<OrderFilledEventArgs>(m_ts_OrderFilled);
                m_ts.OrderRejected += new EventHandler<OrderRejectedEventArgs>(m_ts_OrderRejected);
                m_ts.Start();
            }
            else
            {
                Console.WriteLine("Launch of AutospreaderInstrument to {0} was unsuccessful.", e.OrderFeed.Name);
            }
        }
        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();
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {

                    // Shutdown all subscriptions
                    if (req1 != null)
                    {
                        req1.Dispose();
                        req1 = null;
                    }
                    if (req2 != null)
                    {
                        req2.Dispose();
                        req2 = null;
                    }
                    if (casReq != null)
                    {
                        casReq.Dispose();
                        casReq = null;
                    }
                    if (ts != null)
                    {
                        ts.Dispose();
                        ts = null;
                    }

                    // Shutdown the Dispatcher
                    if (disp != null)
                    {
                        disp.BeginInvokeShutdown();
                        disp = null;
                    }

                    // Shutdown the TT API
                    if (apiInstance != null)
                    {
                        apiInstance.Shutdown();
                        apiInstance = null;
                    }
                }
            }

            disposed = true;
        }