Example #1
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_fs != null)
                    {
                        m_fs.FillAdded        -= m_fs_FillAdded;
                        m_fs.FillBookDownload -= m_fs_FillBookDownload;
                        m_fs.FillListEnd      -= m_fs_FillListEnd;
                        m_fs.FillListStart    -= m_fs_FillListStart;

                        m_fs.Dispose();
                        m_fs = null;
                    }

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

                    m_disposed = true;
                }
            }
        }
        /// <summary>
        /// ConnectionStatusUpdate callback.
        /// Give feedback to the user that there was an issue starting up and connecting to XT.
        /// </summary>
        void ttapiInstance_ConnectionStatusUpdate(object sender, ConnectionStatusUpdateEventArgs e)
        {
            if (e.Status.IsSuccess)
            {
                this.Enabled = true;

                UpdateStatusBar("Total Fill Count: " + m_FillCount);

                // Create the Fills Subscription
                m_fillSubscription = new FillsSubscription(m_TTAPI.Session, Dispatcher.Current);

                // Subscribe to all Fill Events
                m_fillSubscription.FillListEnd += new EventHandler<FillListEventArgs>(m_FillSubscription_FillListEnd);
                m_fillSubscription.FillListStart += new EventHandler<FillListEventArgs>(m_FillSubscription_FillListStart);
                m_fillSubscription.FillBookDownload += new EventHandler<FillBookDownloadEventArgs>(m_FillSubscription_FillBookDownload);
                m_fillSubscription.FillAdded += new EventHandler<FillAddedEventArgs>(m_FillSubscription_FillAdded);
                m_fillSubscription.FillDeleted += new EventHandler<FillDeletedEventArgs>(m_FillSubscription_FillDeleted);
                m_fillSubscription.FillAmended += new EventHandler<FillAmendedEventArgs>(m_FillSubscription_FillAmended);

                // Start the subscription
                m_fillSubscription.Start();
            }
            else
            {
                MessageBox.Show(String.Format("ConnectionStatusUpdate: {0}", e.Status.StatusMessage));
            }
        }
Example #3
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Event notification for status of authentication. </summary>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public void m_api_TTAPIStatusUpdate(object sender, TTAPIStatusUpdateEventArgs e)
        {
            Console.WriteLine("TTAPIStatusUpdate: {0}", e);
            if (e.IsReady == false)
            {
                // TODO: Do any connection lost processing here
                return;
            }
            // TODO: Do any connection up processing here
            //       note: can happen multiple times with your application life cycle

            // can get status multiple times - do not create subscription if it exists
            //
            if (object.ReferenceEquals(m_fs, null) == false)
            {
                return;
            }

            // Status is up and we have not started a subscription yet

            // start the fill processing
            m_apiInstance.StartFillFeed();

            m_fs                   = new FillsSubscription(m_disp);
            m_fs.FillAdded        += m_fs_FillAdded;
            m_fs.FillBookDownload += m_fs_FillBookDownload;

            m_fs.FillListEnd   += m_fs_FillListEnd;
            m_fs.FillListStart += m_fs_FillListStart;
            m_fs.Start();
        }
Example #4
0
        /// <summary>
        /// ConnectionStatusUpdate callback.
        /// Give feedback to the user that there was an issue starting up and connecting to XT.
        /// </summary>
        void ttapiInstance_ConnectionStatusUpdate(object sender, ConnectionStatusUpdateEventArgs e)
        {
            if (e.Status.IsSuccess)
            {
                this.Enabled = true;

                UpdateStatusBar("Total Fill Count: " + m_FillCount);

                // Create the Fills Subscription
                m_fillSubscription = new FillsSubscription(m_TTAPI.Session, Dispatcher.Current);

                // Subscribe to all Fill Events
                m_fillSubscription.FillListEnd      += new EventHandler <FillListEventArgs>(m_FillSubscription_FillListEnd);
                m_fillSubscription.FillListStart    += new EventHandler <FillListEventArgs>(m_FillSubscription_FillListStart);
                m_fillSubscription.FillBookDownload += new EventHandler <FillBookDownloadEventArgs>(m_FillSubscription_FillBookDownload);
                m_fillSubscription.FillAdded        += new EventHandler <FillAddedEventArgs>(m_FillSubscription_FillAdded);
                m_fillSubscription.FillDeleted      += new EventHandler <FillDeletedEventArgs>(m_FillSubscription_FillDeleted);
                m_fillSubscription.FillAmended      += new EventHandler <FillAmendedEventArgs>(m_FillSubscription_FillAmended);

                // Start the subscription
                m_fillSubscription.Start();
            }
            else
            {
                MessageBox.Show(String.Format("ConnectionStatusUpdate: {0}", e.Status.StatusMessage));
            }
        }
Example #5
0
        /// <summary>
        /// Event notification for instrument lookup
        /// </summary>
        public void req_Update(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.Instrument != null && e.Error == null)
            {
                cout("Subscribed to Instrument: {0}", e.Instrument.Key);

                _instruments[GetIid(e.Instrument)].FoundInstrument(e.Instrument);

                // Market Depth subscription (or just Inside Market if you change the PriceSubscriptionSettings)
                var prcSub = new PriceSubscription(e.Instrument, Dispatcher.Current);
                //psSub.Settings = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
                prcSub.Settings       = new PriceSubscriptionSettings(PriceSubscriptionType.MarketDepth);
                prcSub.FieldsUpdated += new FieldsUpdatedEventHandler(m_prc_FieldsUpdated);
                m_lprc.Add(prcSub);
                prcSub.Start();

                // Time & Sales subscription
                var tsSub = new TimeAndSalesSubscription(e.Instrument, Dispatcher.Current);
                tsSub.Update += new EventHandler <TimeAndSalesEventArgs>(tsSub_Update);
                m_lts.Add(tsSub);
                tsSub.Start();

                // Fills subscription
                var filSub = new FillsSubscription(m_TTAPI.Session, Dispatcher.Current);
                filSub.FillAdded        += new EventHandler <FillAddedEventArgs>(m_fil_FillAdded);
                filSub.FillAmended      += new EventHandler <FillAmendedEventArgs>(m_fil_FillAmended);
                filSub.FillBookDownload += new EventHandler <FillBookDownloadEventArgs>(m_fil_FillBookDownload);
                filSub.FillDeleted      += new EventHandler <FillDeletedEventArgs>(m_fil_FillDeleted);
                filSub.FillListEnd      += new EventHandler <FillListEventArgs>(m_fil_FillListEnd);
                filSub.FillListStart    += new EventHandler <FillListEventArgs>(m_fil_FillListStart);
                m_lfil.Add(filSub);
                filSub.Start();

                // Trade Subscription (to listen for order / fill events only for orders submitted through it)
                var trdSub = new InstrumentTradeSubscription(m_TTAPI.Session, Dispatcher.Current, e.Instrument, true, true, false, false);
                trdSub.OrderUpdated     += new EventHandler <OrderUpdatedEventArgs>(m_trd_OrderUpdated);
                trdSub.OrderAdded       += new EventHandler <OrderAddedEventArgs>(m_trd_OrderAdded);
                trdSub.OrderDeleted     += new EventHandler <OrderDeletedEventArgs>(m_trd_OrderDeleted);
                trdSub.OrderFilled      += new EventHandler <OrderFilledEventArgs>(m_trd_OrderFilled);
                trdSub.OrderRejected    += new EventHandler <OrderRejectedEventArgs>(m_trd_OrderRejected);
                m_dtrd[e.Instrument.Key] = trdSub;
                trdSub.Start();
            }
            else if (e.IsFinal)
            {
                // Instrument was not found and TT API has given up looking for it
                cout("Cannot find instrument, and giving up: {0}", e.Error.Message);
                Dispose();
            }
            else
            {
                cout("Cannot find instrument: {0}", e.Error.Message);
            }
        }
 public void Subscribe2OrderFills(object sender, AuthenticationStatusUpdateEventArgs e)
 {
     if (e.Status.IsSuccess)
     {
         // Start a fill subscription
         Fs            = new FillsSubscription(m_apiInstance.Session, Dispatcher.Current);
         Fs.FillAdded += new EventHandler <FillAddedEventArgs>(FillAddedEventHandler);
         Fs.Start();
     }
     else
     {
         Console.WriteLine("TT Login failed: {0}", e.Status.StatusMessage);
         Dispose();
     }
 }
Example #7
0
        private void CreateFillsSubscription()
        {
            Message("Creating FillsSubscription...");

            FillsSubscription fs = new FillsSubscription(apiInstance.Session, Dispatcher.Current);

            fs.FillListStart    += new EventHandler <FillListEventArgs>(fs_FillListStart);
            fs.FillBookDownload += new EventHandler <FillBookDownloadEventArgs>(fs_FillBookDownload);
            fs.FillListEnd      += new EventHandler <FillListEventArgs>(fs_FillListEnd);
            fs.FillAdded        += new EventHandler <FillAddedEventArgs>(fs_FillAdded);
            fs.FillDeleted      += new EventHandler <FillDeletedEventArgs>(fs_FillDeleted);
            fs.FillAmended      += new EventHandler <FillAmendedEventArgs>(fs_FillAmended);
            fs.Start();

            Message("FillsSubscription created.");
        }
 public void apiInstance_AuthenticationStatusUpdate(object sender, AuthenticationStatusUpdateEventArgs e)
 {
     if (e.Status.IsSuccess)
     {
         fs = new FillsSubscription(apiInstance.Session, Dispatcher.Current);
         fs.FillListStart += new EventHandler<FillListEventArgs>(fs_FillListStart);
         fs.FillBookDownload += new EventHandler<FillBookDownloadEventArgs>(fs_FillBookDownload);
         fs.FillListEnd += new EventHandler<FillListEventArgs>(fs_FillListEnd);
         fs.FillAdded += new EventHandler<FillAddedEventArgs>(fs_FillAdded);
         fs.FillDeleted += new EventHandler<FillDeletedEventArgs>(fs_FillDeleted);
         fs.FillAmended += new EventHandler<FillAmendedEventArgs>(fs_FillAmended);
         fs.Start();
     }
     else
     {
         Console.WriteLine("Login Failed: " + e.Status.StatusMessage);
         Dispose();
     }
 }
 /// <summary>
 /// Event notification for status of authentication
 /// </summary>
 public void apiInstance_AuthenticationStatusUpdate(object sender, AuthenticationStatusUpdateEventArgs e)
 {
     if (e.Status.IsSuccess)
     {
         // Start a fill subscription
         m_fs                   = new FillsSubscription(m_apiInstance.Session, Dispatcher.Current);
         m_fs.FillAdded        += new EventHandler <FillAddedEventArgs>(m_fs_FillAdded);
         m_fs.FillAmended      += new EventHandler <FillAmendedEventArgs>(m_fs_FillAmended);
         m_fs.FillBookDownload += new EventHandler <FillBookDownloadEventArgs>(m_fs_FillBookDownload);
         m_fs.FillDeleted      += new EventHandler <FillDeletedEventArgs>(m_fs_FillDeleted);
         m_fs.FillListEnd      += new EventHandler <FillListEventArgs>(m_fs_FillListEnd);
         m_fs.FillListStart    += new EventHandler <FillListEventArgs>(m_fs_FillListStart);
         m_fs.Rollover         += new EventHandler <RolloverEventArgs>(m_fs_Rollover);
         m_fs.Start();
     }
     else
     {
         Console.WriteLine("TT Login failed: {0}", e.Status.StatusMessage);
         Dispose();
     }
 }
Example #10
0
        public void CreateFillSubscription()
        {
            if (_dispatcher.InvokeRequired())
            {
                _dispatcher.BeginInvoke(() =>
                {
                    CreateFillSubscription();
                });
                return;
            }

            Dispatcher dispatcher = Dispatcher.Current;

            Console.WriteLine("Creating Fill Subscription...");

            _fs = new FillsSubscription(_apiSession, dispatcher);
            _fs.FillListStart    += new EventHandler <FillListEventArgs>(fs_FillListStart);
            _fs.FillBookDownload += new EventHandler <FillBookDownloadEventArgs>(fs_FillBookDownload);
            _fs.FillListEnd      += new EventHandler <FillListEventArgs>(fs_FillListEnd);
            _fs.FillAdded        += new EventHandler <FillAddedEventArgs>(fs_FillAdded);
            _fs.FillDeleted      += new EventHandler <FillDeletedEventArgs>(fs_FillDeleted);
            _fs.FillAmended      += new EventHandler <FillAmendedEventArgs>(fs_FillAmended);
            _fs.Start();

            _ts = new TradeSubscription(_apiSession, dispatcher);
            _ts.FillBookDownload       += new EventHandler <FillBookDownloadEventArgs>(ts_FillBookDownload);
            _ts.FillListEnd            += new EventHandler <FillListEventArgs>(ts_FillListEnd);
            _ts.FillListStart          += new EventHandler <FillListEventArgs>(ts_FillListStart);
            _ts.FillAmended            += new EventHandler <FillAmendedEventArgs>(ts_FillAmended);
            _ts.FillRecordAdded        += new EventHandler <FillAddedEventArgs>(ts_FillRecordAdded);
            _ts.AdminFillAdded         += new EventHandler <FillAddedEventArgs>(ts_AdminFillAdded);
            _ts.AdminFillDeleted       += new EventHandler <FillDeletedEventArgs>(ts_AdminFillDeleted);
            _ts.Rollover               += new EventHandler <RolloverEventArgs>(ts_Rollover);
            _ts.TradeSubscriptionReset += new EventHandler <TradeSubscriptionResetEventArgs>(ts_TradeSubscriptionReset);
            //ts.EnablePNL = true;
            //ts.ProfitLossChanged += new EventHandler<ProfitLossChangedEventArgs>(ts_ProfitLossChanged);
            _ts.Start();

            Console.WriteLine("Fill Subscription created.");
        }
Example #11
0
        /// <summary>
        /// Dispose of all the TT API objects and shutdown the TT API
        /// </summary>
        public void shutdownTTAPI()
        {
            if (!m_shutdownInProcess)
            {
                // Dispose of all request objects
                if (m_fillSubscription != null)
                {
                    m_fillSubscription.FillListEnd      -= m_FillSubscription_FillListEnd;
                    m_fillSubscription.FillListStart    -= m_FillSubscription_FillListStart;
                    m_fillSubscription.FillBookDownload -= m_FillSubscription_FillBookDownload;
                    m_fillSubscription.FillAdded        -= m_FillSubscription_FillAdded;
                    m_fillSubscription.FillDeleted      -= m_FillSubscription_FillDeleted;
                    m_fillSubscription.FillAmended      -= m_FillSubscription_FillAmended;
                    m_fillSubscription.Dispose();
                    m_fillSubscription = null;
                }

                TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted);
                TTAPI.Shutdown();
            }

            // only run shutdown once
            m_shutdownInProcess = true;
        }
        /// <summary>
        /// Dispose of all the TT API objects and shutdown the TT API 
        /// </summary>
        public void shutdownTTAPI()
        {
            if (!m_shutdownInProcess)
            {
                // Dispose of all request objects
                if (m_fillSubscription != null)
                {
                    m_fillSubscription.FillListEnd -= m_FillSubscription_FillListEnd;
                    m_fillSubscription.FillListStart -= m_FillSubscription_FillListStart;
                    m_fillSubscription.FillBookDownload -= m_FillSubscription_FillBookDownload;
                    m_fillSubscription.FillAdded -= m_FillSubscription_FillAdded;
                    m_fillSubscription.FillDeleted -= m_FillSubscription_FillDeleted;
                    m_fillSubscription.FillAmended -= m_FillSubscription_FillAmended;
                    m_fillSubscription.Dispose();
                    m_fillSubscription = null;
                }

                TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted);
                TTAPI.Shutdown();
            }

            // only run shutdown once
            m_shutdownInProcess = true;
        }
 public void Subscribe2OrderFills(object sender, AuthenticationStatusUpdateEventArgs e)
 {
      if (e.Status.IsSuccess)
     {
         // Start a fill subscription
         Fs = new FillsSubscription(m_apiInstance.Session, Dispatcher.Current);
         Fs.FillAdded += new EventHandler<FillAddedEventArgs>(FillAddedEventHandler);
         Fs.Start();
     }
      else
      {
          Console.WriteLine("TT Login failed: {0}", e.Status.StatusMessage);
          Dispose();
      }
 }
        /// <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_fs != null)
                    {
                        m_fs.FillAdded -= m_fs_FillAdded;
                        m_fs.FillAmended -= m_fs_FillAmended;
                        m_fs.FillBookDownload -= m_fs_FillBookDownload;
                        m_fs.FillDeleted -= m_fs_FillDeleted;
                        m_fs.FillListEnd -= m_fs_FillListEnd;
                        m_fs.FillListStart -= m_fs_FillListStart;
                        m_fs.Rollover -= m_fs_Rollover;
                        m_fs.Dispose();
                        m_fs = null;
                    }

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

                    m_disposed = true;
                }
            }
        }
 /// <summary>
 /// Event notification for status of authentication
 /// </summary>
 public void apiInstance_AuthenticationStatusUpdate(object sender, AuthenticationStatusUpdateEventArgs e)
 {
     if (e.Status.IsSuccess)
     {
         // Start a fill subscription
         m_fs = new FillsSubscription(m_apiInstance.Session, Dispatcher.Current);
         m_fs.FillAdded += new EventHandler<FillAddedEventArgs>(m_fs_FillAdded);
         m_fs.FillAmended += new EventHandler<FillAmendedEventArgs>(m_fs_FillAmended);
         m_fs.FillBookDownload += new EventHandler<FillBookDownloadEventArgs>(m_fs_FillBookDownload);
         m_fs.FillDeleted += new EventHandler<FillDeletedEventArgs>(m_fs_FillDeleted);
         m_fs.FillListEnd += new EventHandler<FillListEventArgs>(m_fs_FillListEnd);
         m_fs.FillListStart += new EventHandler<FillListEventArgs>(m_fs_FillListStart);
         m_fs.Rollover += new EventHandler<RolloverEventArgs>(m_fs_Rollover);
         m_fs.Start();
     }
     else
     {
         Console.WriteLine("TT Login failed: {0}", e.Status.StatusMessage);
         Dispose();
     }
 }
        /// <summary>
        /// Event notification for status of authentication
        /// </summary>
        public void apiInstance_AuthenticationStatusUpdate(object sender, AuthenticationStatusUpdateEventArgs e)
        {
            if (e.Status.IsSuccess)
            {
                // lookup an instrument
                m_req = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current,
                    new ProductKey(MarketKey.Cme, ProductType.Spread, "CL"),
                    "Calendar: 1xCL Nov16:-1xDec16");
                m_req.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(m_req_Update);
                m_req.Start();

                m_fs = new FillsSubscription(m_apiInstance.Session, Dispatcher.Current);
                m_fs.FillAdded += new EventHandler<FillAddedEventArgs>(m_fs_FillAdded);
                m_fs.Start();
            }
            else
            {
                Console.WriteLine("TT Login failed: {0}", e.Status.StatusMessage);
                Dispose();
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {

                    // Shutdown all subscriptions
                    if (fs != null)
                    {
                        fs.Dispose();
                        fs = null;
                    }

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

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

            disposed = true;
        }