Exemplo n.º 1
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_priceSubscription != null)
                {
                    m_priceSubscription.FieldsUpdated -= priceSubscription_FieldsUpdated;
                    m_priceSubscription.Dispose();
                    m_priceSubscription = null;
                }

                if (m_customerDefaultsSubscription != null)
                {
                    m_customerDefaultsSubscription.CustomerDefaultsChanged -= m_customerDefaultsSubscription_CustomerDefaultsChanged;
                    m_customerDefaultsSubscription.Dispose();
                    m_customerDefaultsSubscription = null;
                }

                if (m_instrumentTradeSubscription != null)
                {
                    m_instrumentTradeSubscription.OrderAdded    -= m_instrumentTradeSubscription_OrderAdded;
                    m_instrumentTradeSubscription.OrderRejected -= m_instrumentTradeSubscription_OrderRejected;
                    m_instrumentTradeSubscription.Dispose();
                    m_instrumentTradeSubscription = null;
                }

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

            // only run shutdown once
            m_shutdownInProcess = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Instrument request completed event.
        /// </summary>
        void instrRequest_Completed(object sender, TT.InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.IsFinal && e.Instrument != null)
            {
                try
                {
                    cout("TT API FindInstrument {0}", e.Instrument.Name);

                    TTInstrument ttinstr = _instruments.Values.First(tti => tti.InstrumentKey == e.Instrument.Key);
                    ttinstr.FoundInstrument(e.Instrument);

                    // subscribe for price updates
                    m_priceSubscription                = new TT.PriceSubscription(e.Instrument, TT.Dispatcher.Current);
                    m_priceSubscription.Settings       = new TT.PriceSubscriptionSettings(TT.PriceSubscriptionType.InsideMarket);
                    m_priceSubscription.FieldsUpdated += new TT.FieldsUpdatedEventHandler(priceSubscription_FieldsUpdated);
                    m_priceSubscription.Start();

                    // subscribe for trade updates
                    m_instrumentTradeSubscription                = new InstrumentTradeSubscription(m_TTAPI.Session, TT.Dispatcher.Current, e.Instrument);
                    m_instrumentTradeSubscription.OrderAdded    += new EventHandler <TT.OrderAddedEventArgs>(m_instrumentTradeSubscription_OrderAdded);
                    m_instrumentTradeSubscription.OrderRejected += new EventHandler <TT.OrderRejectedEventArgs>(m_instrumentTradeSubscription_OrderRejected);
                    m_instrumentTradeSubscription.Start();
                }
                catch (Exception err)
                {
                    ErrorMessage("TT API FindInstrument Exception: {0}", err.Message);
                }
            }
            else if (e.IsFinal)
            {
                cout("TT API FindInstrument Instrument Not Found: {0}", e.Error);
            }
            else
            {
                cout("TT API FindInstrument Instrument Not Found: (Still Searching) {0}", e.Error);
            }
        }