示例#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_req != null)
                    {
                        m_req.Update -= m_req_Update;
                        m_req.Dispose();
                        m_req = null;
                    }
                    if (m_ps != null)
                    {
                        m_ps.FieldsUpdated -= m_ps_FieldsUpdated;
                        m_ps.Dispose();
                        m_ps = null;
                    }

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

                    m_disposed = true;
                }
            }
        }
        /// <summary>
        /// Create subscriptions and update the GUI.
        /// </summary>
        /// <param name="instrument">Instrument to create subscriptions with.</param>
        private void instrumentFound(Instrument instrument)
        {
            txtExchange.Text    = instrument.Key.MarketKey.Name;
            txtProduct.Text     = instrument.Key.ProductKey.Name;
            txtProductType.Text = instrument.Key.ProductKey.Type.Name;
            txtContract.Text    = instrument.Name;

            m_priceSubscription = new PriceSubscription(instrument, Dispatcher.Current);
            m_priceSubscription.FieldsUpdated += new FieldsUpdatedEventHandler(m_priceSubscription_FieldsUpdated);
            m_priceSubscription.Start();

            m_instrumentTradeSubscription                = new InstrumentTradeSubscription(m_TTAPI.Session, Dispatcher.Current, instrument);
            m_instrumentTradeSubscription.OrderAdded    += new EventHandler <OrderAddedEventArgs>(m_instrumentTradeSubscription_OrderAdded);
            m_instrumentTradeSubscription.OrderRejected += new EventHandler <OrderRejectedEventArgs>(m_instrumentTradeSubscription_OrderRejected);
            m_instrumentTradeSubscription.Start();

            populateOrderFeedDropDown(instrument);

            // Enable the user interface items.
            txtQuantity.Enabled       = true;
            cboOrderType.Enabled      = true;
            comboBoxOrderFeed.Enabled = true;
            cboCustomer.Enabled       = true;
            btnBuy.Enabled            = true;
            btnSell.Enabled           = true;
        }
        /// <summary>
        /// Event notification for instrument lookup
        /// </summary>
        void m_req_Update(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.Instrument != null && e.Error == null)
            {
                // Instrument was found
                Console.WriteLine("Found: {0}", e.Instrument.Name);

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

                // Create a TradeSubscription to listen for order / fill events only for orders submitted through it
                m_ts = new InstrumentTradeSubscription(m_apiInstance.Session, Dispatcher.Current, e.Instrument, 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 if (e.IsFinal)
            {
                // Instrument was not found and TT API has given up looking for it
                Console.WriteLine("Cannot find instrument: {0}", e.Error.Message);
                Dispose();
            }
        }
        /// <summary>
        /// Instrument request completed event.
        /// </summary>
        void instrRequest_Completed(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.IsFinal && e.Instrument != null)
            {
                try
                {
                    UpdateStatusBar("Instrument Found.");
                    Console.WriteLine(String.Format("TT API FindInstrument {0}", e.Instrument.Name));

                    if (m_priceSubscription != null)
                    {
                        m_priceSubscription.Dispose();
                        m_priceSubscription = null;
                    }

                    // subscribe for price updates
                    m_priceSubscription                = new PriceSubscription(e.Instrument, Dispatcher.Current);
                    m_priceSubscription.Settings       = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
                    m_priceSubscription.FieldsUpdated += new FieldsUpdatedEventHandler(priceSubscription_FieldsUpdated);
                    m_priceSubscription.Start();
                }
                catch (Exception err)
                {
                    Console.WriteLine(String.Format("TT API FindInstrument Exception: {0}", err.Message));
                }
            }
            else if (e.IsFinal)
            {
                Console.WriteLine(String.Format("TT API FindInstrument Instrument Not Found: {0}", e.Error));
            }
            else
            {
                Console.WriteLine(String.Format("TT API FindInstrument Instrument Not Found: (Still Searching) {0}", e.Error));
            }
        }
示例#5
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Event notification for instrument lookup. </summary>
        /// <param name="sender">   Source of the event. </param>
        /// <param name="e">        Instrument lookup subscription event information. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        void m_instrLookupRequest_OnData(object sender, InstrumentLookupEventArgs e)
        {
            if (e.Event == ProductDataEvent.Found)
            {
                // Instrument was found
                Instrument instrument = e.InstrumentLookup.Instrument;
                Console.WriteLine("Found: {0}", instrument);

                // Subscribe for Detailed Depth Data
                m_priceSubsciption                = new PriceSubscription(instrument, tt_net_sdk.Dispatcher.Current);
                m_priceSubsciption.Settings       = new PriceSubscriptionSettings(PriceSubscriptionType.DetailedDepth);
                m_priceSubsciption.FieldsUpdated += m_priceSubscription_FieldsUpdated;
                m_priceSubsciption.Start();

                //subscribe for Estimated Position in Queue
                m_estimatedPositionInQueueSubscription = new EstimatedPositionInQueueSubscription(tt_net_sdk.Dispatcher.Current);
                m_estimatedPositionInQueueSubscription.EstimatedPositionInQueueUpdated += M_estimatedPositionInQueueSubscription_EstimatedPositionInQueueUpdated;
                m_estimatedPositionInQueueSubscription.Start();
            }
            else if (e.Event == ProductDataEvent.NotAllowed)
            {
                Console.WriteLine("Not Allowed : Please check your Token access");
            }
            else
            {
                // Instrument was not found and TT API has given up looking for it
                Console.WriteLine("Cannot find instrument: {0}", e.Message);
            }
        }
示例#6
0
        void m_instrLookupRequest_OnData(object sender, InstrumentLookupEventArgs e)
        {
            if (e.Event == ProductDataEvent.Found)
            {
                // Instrument was found
                m_instrument = e.InstrumentLookup.Instrument;
                Console.WriteLine("Found: {0}", m_instrument);

                AlgoLookupSubscription algoLookupSubscription = new AlgoLookupSubscription(tt_net_sdk.Dispatcher.Current, "TT Iceberg");
                algoLookupSubscription.OnData += AlgoLookupSubscription_OnData;
                algoLookupSubscription.GetAsync();

                // Subscribe for market Data
                m_priceSubscription                = new PriceSubscription(m_instrument, tt_net_sdk.Dispatcher.Current);
                m_priceSubscription.Settings       = new PriceSubscriptionSettings(PriceSubscriptionType.MarketDepth);
                m_priceSubscription.FieldsUpdated += m_priceSubscription_FieldsUpdated;
                m_priceSubscription.Start();
            }
            else if (e.Event == ProductDataEvent.NotAllowed)
            {
                Console.WriteLine("Not Allowed : Please check your Token access");
            }
            else
            {
                // Instrument was not found and TT API has given up looking for it
                Console.WriteLine("Cannot find instrument: {0}", e.Message);
                Dispose();
            }
        }
示例#7
0
 /// <summary>
 /// Create a price subscription
 /// </summary>
 /// <param name="instrument">Instrument to subscribe to</param>
 public void StartPriceSubscription(Instrument instrument)
 {
     m_priceSubscription                = new PriceSubscription(instrument, m_dispatcher);
     m_priceSubscription.Settings       = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
     m_priceSubscription.FieldsUpdated += new FieldsUpdatedEventHandler(priceSubscription_FieldsUpdated);
     m_priceSubscription.Start();
 }
示例#8
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);
            }
        }
        /// <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_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;
                }

                if (m_priceSubscription != null)
                {
                    m_priceSubscription.FieldsUpdated -= m_priceSubscription_FieldsUpdated;
                    m_priceSubscription.Dispose();
                    m_priceSubscription = null;
                }

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

            // only run shutdown once
            m_shutdownInProcess = true;
        }
示例#10
0
 public Subscription(Instrument instr, Dispatcher dsptr, PriceSubscriptionType priceSubscriptionType, IObserver <FieldsUpdatedEventArgs> obsvr)
 {
     _obsvrRaw = obsvr;
     _pxSub    = new PriceSubscription(instr, dsptr)
     {
         Settings = new PriceSubscriptionSettings(priceSubscriptionType)
     };
     _pxSub.FieldsUpdated += PxSub_FieldsUpdated;
     _pxSub.Start();
 }
示例#11
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);
            }
        }
示例#12
0
 public void req_Update(object sender, InstrumentLookupSubscriptionEventArgs e)
 {
     if (e.Instrument != null && e.Error == null)
     {
         ps = new PriceSubscription(e.Instrument, Dispatcher.Current)
         {
             Settings = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket)
         }; ps.FieldsUpdated += new FieldsUpdatedEventHandler(ps_FieldsUpdated); ps.Start();
         tsSub      = new TimeAndSalesSubscription(e.Instrument, Dispatcher.Current); tsSub.Update += new EventHandler <TimeAndSalesEventArgs>(tsSub_Update); tsSub.Start();
         Instrument = e.Instrument; SetUp();
     }
 }
示例#13
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;
                }
            }
        }
示例#14
0
        public void Dispose()
        {
            lock (m_Lock)
            {
                if (!m_isDisposed)
                {
                    // Unattached callbacks and dispose of all subscriptions
                    if (m_instrLookupRequest != null)
                    {
                        m_instrLookupRequest.OnData -= m_instrLookupRequest_OnData;
                        m_instrLookupRequest.Dispose();
                        m_instrLookupRequest = null;
                    }

                    if (m_algoLookupSubscription != null)
                    {
                        m_algoLookupSubscription.OnData -= AlgoLookupSubscription_OnData;
                        m_algoLookupSubscription.Dispose();
                        m_algoLookupSubscription = null;
                    }

                    if (m_priceSubscription != null)
                    {
                        m_priceSubscription.FieldsUpdated -= m_priceSubscription_FieldsUpdated;
                        m_priceSubscription.Dispose();
                        m_priceSubscription = null;
                    }

                    if (m_algoTradeSubscription != null)
                    {
                        m_algoTradeSubscription.OrderUpdated        -= m_algoTradeSubscription_OrderUpdated;
                        m_algoTradeSubscription.OrderAdded          -= m_algoTradeSubscription_OrderAdded;
                        m_algoTradeSubscription.OrderDeleted        -= m_algoTradeSubscription_OrderDeleted;
                        m_algoTradeSubscription.OrderFilled         -= m_algoTradeSubscription_OrderFilled;
                        m_algoTradeSubscription.OrderRejected       -= m_algoTradeSubscription_OrderRejected;
                        m_algoTradeSubscription.ExportValuesUpdated -= m_algoTradeSubscription_ExportValuesUpdated;
                        m_algoTradeSubscription.AlertsFired         -= m_algoTradeSubscription_AlertsUpdated;
                        m_algoTradeSubscription.Dispose();
                        m_algoTradeSubscription = null;
                    }

                    m_isDisposed = true;
                }

                TTAPI.Shutdown();
            }
        }
示例#15
0
        void req_Update(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            Console.WriteLine("req_Update");
            if (e.Instrument != null && e.Error == null)
            {
                tslblInfo.Text = "SUBSCRIBED: " + e.Instrument.Name;
                Message("SUBSCRIBED: " + e.Instrument.Name);
                // if this instrument is one of our managed hedges, then add it
                // to the managed hedge dictionary
                foreach (InstrumentInfo info in managedHedgeList)
                {
                    if (info.ProductKey == e.Instrument.Product.Key && e.Instrument.Name.Contains(info.Contract)) // && info.Contract.Equals(e.Instrument.Name))
                    {
                        info.Instrument    = e.Instrument;
                        info.InstrumentKey = e.Instrument.Key;
                        managedHedges.Add(e.Instrument.Key, info);
                    }
                }

                // iterate order feeds enabled for each instrument
                foreach (OrderFeed oFeed in e.Instrument.GetValidOrderFeeds())
                {
                    if (oFeed.IsTradingEnabled)
                    {
                        Console.WriteLine("Order feed {0} is enabled for trading", oFeed.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Order feed {0} is NOT enabled for trading", oFeed.ToString());
                    }
                }
                // successfully subscribed to an instrument so request prices

                PriceSubscription priceSub = new PriceSubscription(e.Instrument, Dispatcher.Current);
                priceSub.Settings       = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
                priceSub.FieldsUpdated += new FieldsUpdatedEventHandler(priceSub_FieldsUpdated);
                priceSub.Start();

                InstrumentTradeSubscription its = new InstrumentTradeSubscription(apiInstance.Session, Dispatcher.Current, e.Instrument);
                its.Start();
            }
            else if (e.IsFinal)
            {
                // Instrument was not found and TTAPI has given up looking for it
                tslblInfo.Text = "ERROR: " + e.Error.Message;
            }
        }
示例#16
0
 private void ReqUpdate(object sender, InstrumentLookupSubscriptionEventArgs e)
 {
     if (e.Instrument != null && e.Error == null)
     {
         // Subscribe for Inside Market Data
         var priceSub = new PriceSubscription(e.Instrument, Dispatcher.Current);
         priceSub.Settings       = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
         priceSub.FieldsUpdated += PriceFieldsUpdated;
         m_ltsSub.Add(priceSub);
         priceSub.Start();
     }
     else if (e.IsFinal)
     {
         // Instrument was not found and TT API has given up looking for it
         log.Info($"Cannot find instrument: {e.Error.Message}");
         Dispose();
     }
 }
        public PriceSubscription Get(int enterprise)
        {
            var s = new PriceSubscription
            {
                Currency = "EUR",
                CostToRenovation = 100,
                Credit = 55,
                
                CurrencyRates = new Currency[]
                {
                    new Currency{ Code="EUR", Symbol="€", Rate = 1.00},
                    new Currency{ Code="USD", Symbol="$", Rate = 1.45},
                    new Currency{ Code="GBP", Symbol="£", Rate = 0.82},
                }
            };

            return s;
        }
示例#18
0
            protected virtual void Dispose(bool disposing)
            {
                if (!m_disposed)
                {
                    if (disposing)
                    {
                        if (m_priceSubscription != null)
                        {
                            m_priceSubscription.FieldsUpdated -= priceSubscription_FieldsUpdated;
                            m_priceSubscription.Dispose();
                            m_priceSubscription = null;
                        }

                        m_dispatcher.BeginInvokeShutdown();
                    }

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

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

            // only run shutdown once
            m_shutdownInProcess = true;
        }
示例#20
0
        /// <summary>
        /// Event notification for instrument lookup
        /// </summary>
        void m_req_Update(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.Instrument != null && e.Error == null)
            {
                // Instrument was found
                Console.WriteLine("Found: {0}", e.Instrument.Name);

                // Subscribe for Inside Market Data
                m_ps                = new PriceSubscription(e.Instrument, Dispatcher.Current);
                m_ps.Settings       = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
                m_ps.FieldsUpdated += new FieldsUpdatedEventHandler(m_ps_FieldsUpdated);
                m_ps.Start();
            }
            else if (e.IsFinal)
            {
                // Instrument was not found and TT API has given up looking for it
                Console.WriteLine("Cannot find instrument: {0}", e.Error.Message);
                Dispose();
            }
        }
        /// <summary>
        /// Instrument request completed event.
        /// </summary>
        void instrRequest_Completed(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.IsFinal && e.Instrument != null)
            {
                try
                {
                    UpdateStatusBar("Instrument Found.");
                    Console.WriteLine(String.Format("TT API FindInstrument {0}", e.Instrument.Name));

                    // Grab the contract specifications and output to the user
                    this.txtExchange.Text    = e.Instrument.Product.Market.Name;
                    this.txtProduct.Text     = e.Instrument.Product.Name;
                    this.txtProductType.Text = e.Instrument.Product.Type.ToString();
                    this.txtContract.Text    = e.Instrument.GetFormattedName(InstrumentNameFormat.User);

                    if (m_priceSubscription != null)
                    {
                        m_priceSubscription.Dispose();
                        m_priceSubscription = null;
                    }

                    // subscribe for price updates
                    m_priceSubscription                = new PriceSubscription(e.Instrument, Dispatcher.Current);
                    m_priceSubscription.Settings       = new PriceSubscriptionSettings(PriceSubscriptionType.MarketDepth);
                    m_priceSubscription.FieldsUpdated += new FieldsUpdatedEventHandler(priceSubscription_FieldsUpdated);
                    m_priceSubscription.Start();
                }
                catch (Exception err)
                {
                    Console.WriteLine(String.Format("TT API FindInstrument Exception: {0}", err.Message));
                }
            }
            else if (e.IsFinal)
            {
                Console.WriteLine(String.Format("TT API FindInstrument Instrument Not Found: {0}", e.Error));
            }
            else
            {
                Console.WriteLine(String.Format("TT API FindInstrument Instrument Not Found: (Still Searching) {0}", e.Error));
            }
        }
示例#22
0
        void ils_Update(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            Console.WriteLine("ils_Update");
            if (e.Instrument != null && e.Error == null)
            {
                Message("SUBSCRIBED: " + e.Instrument.Name);

                // iterate order feeds enabled for each instrument
                foreach (OrderFeed oFeed in e.Instrument.GetValidOrderFeeds())
                {
                    if (oFeed.IsTradingEnabled)
                    {
                        Console.WriteLine("Order feed {0} is enabled for trading", oFeed.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Order feed {0} is NOT enabled for trading", oFeed.ToString());
                    }
                }
                // successfully subscribed to an instrument so request prices

                PriceSubscription priceSub = new PriceSubscription(e.Instrument, Dispatcher.Current);
                priceSub.Settings       = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
                priceSub.FieldsUpdated += new FieldsUpdatedEventHandler(priceSub_FieldsUpdated);
                priceSub.Start();

                InstrumentTradeSubscription its = new InstrumentTradeSubscription(apiInstance.Session, Dispatcher.Current, e.Instrument);
                its.EnablePNL          = true;
                its.ProfitLossChanged += new EventHandler <ProfitLossChangedEventArgs>(its_ProfitLossChanged);
                its.Start();

                instruments[e.Instrument.Key].Instrument        = e.Instrument;
                instruments[e.Instrument.Key].TradeSubscription = its;
            }
            else if (e.IsFinal)
            {
                // Instrument was not found and TTAPI has given up looking for it
                ErrorMessage(e.Error.Message);
            }
        }
示例#23
0
        TTInstrument processInstrumentFound(Instrument instrument)
        {
            Dispatcher dispatcher = Dispatcher.Current;
            //Dispatcher dispatcher = _dispatcher;

            PriceSubscription priceSub = new PriceSubscription(instrument, dispatcher);

            if (SubscribeMarketDepth == true)
            {
                priceSub.Settings = new PriceSubscriptionSettings(PriceSubscriptionType.MarketDepth);
            }
            else
            {
                priceSub.Settings = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
            }
            priceSub.FieldsUpdated += new FieldsUpdatedEventHandler(priceSub_FieldsUpdated);
            priceSub.Start();

            InstrumentTradeSubscription its = new InstrumentTradeSubscription(_apiSession, dispatcher, instrument);

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

            if (SubscribeTimeAndSales == true)
            {
                TimeAndSalesSubscription tsSub = new TimeAndSalesSubscription(instrument, dispatcher);
                tsSub.Update += new EventHandler <TimeAndSalesEventArgs>(tsSub_Update);
                tsSub.Start();
            }

            TTInstrument tti = NewTTInstrument(instrument);

            tti.TradeSubscription = its;
            its.Tag = tti;

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

            return(tti);
        }
示例#24
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);
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    // Shutdown all subscriptions
                    if (req != null)
                    {
                        req.Dispose();
                        req = null;
                    }
                    if (ps != null)
                    {
                        ps.Dispose();
                        ps = null;
                    }

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

                    // Shutdown the TT API
                    if (apiInstance != null)
                    {
                        //TTAPI.ShutdownCompleted += new EventHandler();
                        TTAPI.Shutdown();
                        apiInstance = null;
                    }
                }
            }

            disposed = true;
        }
示例#26
0
        public void startPriceSubscriptions(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.Instrument != null && e.Error == null)
            {
                // Instrument was found
                Console.WriteLine("Found: {0}", e.Instrument.Name);

                string TickerDB = TA.TickerConverters.ConvertFromTTAPIFields2DB(e.Instrument.Product.ToString(),
                                                                                e.Instrument.Name.ToString());

                // Subscribe for Market Data
                ps = new PriceSubscription(e.Instrument, Dispatcher.Current);

                if (LiquidDbTickerList.Contains(TickerDB))
                {
                    ps.Settings = new PriceSubscriptionSettings(PriceSubscriptionType.MarketDepth);
                }
                else
                {
                    ps.Settings = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
                }



                ps.FieldsUpdated += new FieldsUpdatedEventHandler(priceUpdatedEventHandler);
                PsDictionary.Add(e.Instrument.Key, ps);
                InstrumentDictionary.Add(e.Instrument.Key, e.Instrument);

                ps.Start();
            }
            else if (e.IsFinal)
            {
                // Instrument was not found and TT API has given up looking for it
                Console.WriteLine("Cannot find instrument: {0}", e.Error.Message);
                Dispose();
            }
        }
示例#27
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Event notification for instrument lookup. </summary>
        /// <param name="sender">   Source of the event. </param>
        /// <param name="e">        Instrument lookup subscription event information. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        void m_instrLookupRequest_OnData(object sender, InstrumentLookupEventArgs e)
        {
            if (e.Event == ProductDataEvent.Found)
            {
                // Instrument was found
                Instrument instrument = e.InstrumentLookup.Instrument;
                Console.WriteLine("Found: {0}", instrument);

                // Subscribe for market Data
                m_priceSubscription                = new PriceSubscription(instrument, tt_net_sdk.Dispatcher.Current);
                m_priceSubscription.Settings       = new PriceSubscriptionSettings(PriceSubscriptionType.MarketDepth);
                m_priceSubscription.FieldsUpdated += m_priceSubscription_FieldsUpdated;
                m_priceSubscription.Start();


                // Create a TradeSubscription to listen for order / fill events only for orders submitted through it
                m_instrumentTradeSubscription = new InstrumentTradeSubscription(tt_net_sdk.Dispatcher.Current, instrument);

                m_instrumentTradeSubscription.OrderUpdated      += new EventHandler <OrderUpdatedEventArgs>(m_instrumentTradeSubscription_OrderUpdated);
                m_instrumentTradeSubscription.OrderAdded        += new EventHandler <OrderAddedEventArgs>(m_instrumentTradeSubscription_OrderAdded);
                m_instrumentTradeSubscription.OrderDeleted      += new EventHandler <OrderDeletedEventArgs>(m_instrumentTradeSubscription_OrderDeleted);
                m_instrumentTradeSubscription.OrderFilled       += new EventHandler <OrderFilledEventArgs>(m_instrumentTradeSubscription_OrderFilled);
                m_instrumentTradeSubscription.OrderRejected     += new EventHandler <OrderRejectedEventArgs>(m_instrumentTradeSubscription_OrderRejected);
                m_instrumentTradeSubscription.OrderBookDownload += new EventHandler <OrderBookDownloadEventArgs>(m_instrumentTradeSubscription_OrderBookDownload);
                m_instrumentTradeSubscription.Start();
            }
            else if (e.Event == ProductDataEvent.NotAllowed)
            {
                Console.WriteLine("Not Allowed : Please check your Token access");
            }
            else
            {
                // Instrument was not found and TT API has given up looking for it
                Console.WriteLine("Cannot find instrument: {0}", e.Message);
                Dispose();
            }
        }
        /// <summary>
        /// Instrument request completed event.
        /// </summary>
        void instrRequest_Completed(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.IsFinal && e.Instrument != null)
            {
                try
                {
                    UpdateStatusBar("Instrument Found.");
                    Console.WriteLine(String.Format("TT API FindInstrument {0}", e.Instrument.Name));

                    // Grab the contract specifications and output to the user
                    this.txtExchange.Text = e.Instrument.Product.Market.Name;
                    this.txtProduct.Text = e.Instrument.Product.Name;
                    this.txtProductType.Text = e.Instrument.Product.Type.ToString();
                    this.txtContract.Text = e.Instrument.GetFormattedName(InstrumentNameFormat.User);

                    if (m_PriceSubscription != null)
                    {
                        m_PriceSubscription.Dispose();
                        m_PriceSubscription = null;
                    }

                    // subscribe for price updates
                    m_PriceSubscription = new PriceSubscription(e.Instrument, Dispatcher.Current);
                    m_PriceSubscription.Settings = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
                    m_PriceSubscription.FieldsUpdated += new FieldsUpdatedEventHandler(priceSubscription_FieldsUpdated);
                    m_PriceSubscription.Start();
                }
                catch (Exception err)
                {
                    Console.WriteLine(String.Format("TT API FindInstrument Exception: {0}", err.Message));
                }
            }
            else if (e.IsFinal)
            {
                Console.WriteLine(String.Format("TT API FindInstrument Instrument Not Found: {0}", e.Error));
            }
            else
            {
                Console.WriteLine(String.Format("TT API FindInstrument Instrument Not Found: (Still Searching) {0}", e.Error));
            }
        }
示例#29
0
        }//Job
        // *****************************************************************
        // ****             Job Processing Methods                      ****
        // *****************************************************************
        /// <summary>
        /// Called by the thread's dispatcher after an outside thread has pushed a new Job.
        /// </summary>
        private void ProcessAJob()
        {
            if (m_isDisposing)
            {
                return;
            }
            Job aJob;

            while (m_InQueue.TryDequeue(out aJob))              // NET 4.5 concurrent queue. No locking needed.
            {
                m_WorkQueue.Enqueue(aJob);                      // push onto my private queue.
            }
            //
            // Process the jobs now.
            //
            while (m_WorkQueue.Count > 0)
            {
                Job job = m_WorkQueue.Dequeue();
                if (job.Product != null)
                {   //
                    // Process Instrument Catalog requests
                    //
                    InstrumentCatalogSubscription instrumentSub = null;
                    if (!m_InstrumentCatalogs.TryGetValue(job.Product.Key, out instrumentSub))
                    {   // Failed to find a subscription.  Create a new one!
                        instrumentSub = new InstrumentCatalogSubscription(job.Product, m_Dispatcher);
                        instrumentSub.InstrumentsUpdated += InstrumentCatalog_InstrumentsUpdated;
                        instrumentSub.Start();                                                  // submit the request.
                        m_InstrumentCatalogs.Add(job.Product.Key, instrumentSub);               // store the catalog object
                        Log.NewEntry(LogLevel.Minor, "{0}: Subscribing to instr catalog for {1}.", this.Name, job.Product.Name);
                    }
                }
                else if (job.InstrumentKey != null && job.Settings == null)
                {   //
                    // Process an Instrument information request
                    //
                    InstrumentLookupSubscription lookup = null;
                    if (!m_InstrumentLookups.TryGetValue(job.InstrumentKey, out lookup))
                    {
                        Log.NewEntry(LogLevel.Major, "{0}: InstrumentLookup {1}.", this.Name, job.InstrumentKey);
                        InstrumentLookupSubscription subscriber = new InstrumentLookupSubscription(m_TTServices.session, m_Dispatcher, job.InstrumentKey);
                        subscriber.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(InstrumentLookup_InstrumentUpdated);
                        m_InstrumentLookups.Add(job.InstrumentKey, subscriber);
                        subscriber.Start();
                    }
                    else
                    {
                        Log.NewEntry(LogLevel.Major, "{0}: InstrumentLookup {1} already submitted.", this.Name, job.InstrumentKey);
                    }
                }
                else if (job.InstrumentKey != null)
                {   //
                    // Subscribe to an instrument
                    //
                    Instrument instrument = null;
                    InstrumentCatalogSubscription catalog       = null;                         // First, find instrument catalog for this instr.
                    InstrumentLookupSubscription  instrumentSub = null;                         // or find a specific instrument subscription.
                    if (m_InstrumentLookups.TryGetValue(job.InstrumentKey, out instrumentSub))
                    {
                        instrument = instrumentSub.Instrument;
                    }
                    else if (m_InstrumentCatalogs.TryGetValue(job.InstrumentKey.ProductKey, out catalog))
                    {
                        catalog.Instruments.TryGetValue(job.InstrumentKey, out instrument);
                    }
                    else
                    {
                        Log.NewEntry(LogLevel.Minor, "{0}: I failed to find instrument key {1}.", this.Name, job.InstrumentKey.ToString());
                        return;
                    }
                    if (instrument != null)
                    {
                        // Subscribe or update pre-existing subscription.
                        PriceSubscription priceSub = null;
                        if (!m_PriceSubscriptions.TryGetValue(instrument.Key, out priceSub))
                        {   // Can't find a subscription, so create one.
                            Log.NewEntry(LogLevel.Major, "{0}: Creating new subscription for {1} with settings {2}.", this.Name, instrument.Name, job.Settings.PriceData);
                            priceSub = new PriceSubscription(instrument, Dispatcher.Current);
                            m_PriceSubscriptions.Add(instrument.Key, priceSub);                                     // add to our list of subscription objects.
                            priceSub.FieldsUpdated += new FieldsUpdatedEventHandler(PriceSubscription_Updated);     // attach my handler to it.
                            priceSub.Settings       = job.Settings;
                            priceSub.Start();
                        }
                        else
                        {
                            Log.NewEntry(LogLevel.Major, "{0}: Found old subscription for {1}.  Overwriting settings {2}.", this.Name, instrument.Name, job.Settings.ToString());
                            priceSub.Settings = job.Settings;
                            priceSub.Start();
                        }
                    }
                }
            } //wend Job in WorkQueue.
        }     //ProcessAJob()
            protected virtual void Dispose(bool disposing)
            {
                if (!m_disposed)
                {
                    if (disposing)
                    {
                        if (m_priceSubscription != null)
                        {
                            m_priceSubscription.FieldsUpdated -= priceSubscription_FieldsUpdated;
                            m_priceSubscription.Dispose();
                            m_priceSubscription = null;
                        }

                        m_dispatcher.BeginInvokeShutdown();
                    }

                    m_disposed = true;
                }
            }
 /// <summary>
 /// Create a price subscription
 /// </summary>
 /// <param name="instrument">Instrument to subscribe to</param>
 public void StartPriceSubscription(Instrument instrument)
 {
     m_priceSubscription = new PriceSubscription(instrument, m_dispatcher);
     m_priceSubscription.Settings = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
     m_priceSubscription.FieldsUpdated += new FieldsUpdatedEventHandler(priceSubscription_FieldsUpdated);
     m_priceSubscription.Start();
 }
        /// <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_req != null)
                    {
                        m_req.Update -= m_req_Update;
                        m_req.Dispose();
                        m_req = 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;
                    }

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

                    m_disposed = true;
                }
            }
        }
        /// <summary>
        /// Event notification for instrument lookup
        /// </summary>
        void m_req_Update(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.Instrument != null && e.Error == null)
            {
                // Instrument was found
                Console.WriteLine("Found: {0}", e.Instrument.Name);

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

                // Create a TradeSubscription to listen for order / fill events only for orders submitted through it
                m_ts = new InstrumentTradeSubscription(m_apiInstance.Session, Dispatcher.Current, e.Instrument, 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 if (e.IsFinal)
            {
                // Instrument was not found and TT API has given up looking for it
                Console.WriteLine("Cannot find instrument: {0}", e.Error.Message);
                Dispose();
            }
        }
        /// <summary>
        /// Instrument request completed event.
        /// </summary>
        void instrRequest_Completed(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.IsFinal && e.Instrument != null)
            {
                try
                {
                    UpdateStatusBar("Instrument Found.");
                    Console.WriteLine(String.Format("TT API FindInstrument {0}", e.Instrument.Name));

                    if (m_priceSubscription != null)
                    {
                        m_priceSubscription.Dispose();
                        m_priceSubscription = null;
                    }

                    // subscribe for price updates
                    m_priceSubscription = new PriceSubscription(e.Instrument, Dispatcher.Current);
                    m_priceSubscription.Settings = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
                    m_priceSubscription.FieldsUpdated += new FieldsUpdatedEventHandler(priceSubscription_FieldsUpdated);
                    m_priceSubscription.Start();
                }
                catch (Exception err)
                {
                    Console.WriteLine(String.Format("TT API FindInstrument Exception: {0}", err.Message));
                }
            }
            else if (e.IsFinal)
            {
                Console.WriteLine(String.Format("TT API FindInstrument Instrument Not Found: {0}", e.Error));
            }
            else
            {
                Console.WriteLine(String.Format("TT API FindInstrument Instrument Not Found: (Still Searching) {0}", e.Error));
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {

                    // Shutdown all subscriptions
                    if (req != null)
                    {
                        req.Dispose();
                        req = null;
                    }
                    if (ps != null)
                    {
                        ps.Dispose();
                        ps = 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;
        }
        /// <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);
            }
        }
        /// <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_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;
                }

                if (m_priceSubscription != null)
                {
                    m_priceSubscription.FieldsUpdated -= m_priceSubscription_FieldsUpdated;
                    m_priceSubscription.Dispose();
                    m_priceSubscription = null;
                }

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

            // only run shutdown once
            m_shutdownInProcess = true;
        }
        /// <summary>
        /// Create subscriptions and update the GUI.
        /// </summary>
        /// <param name="instrument">Instrument to create subscriptions with.</param>
        private void instrumentFound(Instrument instrument)
        {
            txtExchange.Text = instrument.Key.MarketKey.Name;
            txtProduct.Text = instrument.Key.ProductKey.Name;
            txtProductType.Text = instrument.Key.ProductKey.Type.Name;
            txtContract.Text = instrument.Name;

            m_priceSubscription = new PriceSubscription(instrument, Dispatcher.Current);
            m_priceSubscription.FieldsUpdated += new FieldsUpdatedEventHandler(m_priceSubscription_FieldsUpdated);
            m_priceSubscription.Start();

            m_instrumentTradeSubscription = new InstrumentTradeSubscription(m_TTAPI.Session, Dispatcher.Current, instrument);
            m_instrumentTradeSubscription.OrderAdded += new EventHandler<OrderAddedEventArgs>(m_instrumentTradeSubscription_OrderAdded);
            m_instrumentTradeSubscription.OrderRejected += new EventHandler<OrderRejectedEventArgs>(m_instrumentTradeSubscription_OrderRejected);
            m_instrumentTradeSubscription.Start();

            populateOrderFeedDropDown(instrument);

            // Enable the user interface items.
            txtQuantity.Enabled = true;
            cboOrderType.Enabled = true;
            comboBoxOrderFeed.Enabled = true;
            cboCustomer.Enabled = true;
            btnBuy.Enabled = true;
            btnSell.Enabled = true;
        }
示例#39
0
        void m_req_Update(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.Instrument != null && e.Error == null)
            {
                // Instrument was found
                Console.WriteLine("Found: {0}", e.Instrument.Name);

                // Subscribe for Inside Market Data
                m_ps = new PriceSubscription(e.Instrument, Dispatcher.Current);
                m_ps.Settings = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
                m_ps.FieldsUpdated += new FieldsUpdatedEventHandler(m_ps_FieldsUpdated);
                m_ps.Start();
            }
            else if (e.IsFinal)
            {
                // Instrument was not found and TT API has given up looking for it
                Console.WriteLine("Cannot find instrument: {0}", e.Error.Message);
                Dispose();
            }
        }
示例#40
0
        }//Job
        // *****************************************************************
        // ****             Job Processing Methods                      ****
        // *****************************************************************
        /// <summary>
        /// Called by the thread's dispatcher after an outside thread has pushed a new Job.
        /// </summary>
        private void ProcessAJob()
        {
            if (m_isDisposing)
            {
                return;
            }
            Job aJob;

            while (m_InQueue.TryDequeue(out aJob))              // NET 4.5 concurrent queue. No locking needed.
            {
                m_WorkQueue.Enqueue(aJob);                      // push onto my private queue.
            }
            //
            // Process the jobs now.
            //
            while (m_WorkQueue.Count > 0)
            {
                Job job = m_WorkQueue.Dequeue();
                if (job.Product != null)
                {     //
                    if (string.IsNullOrEmpty(job.SeriesName))
                    { // User wants all instruments assoc with this product.
                        //
                        // Process Instrument Catalog requests
                        //
                        InstrumentCatalogSubscription instrumentSub = null;
                        if (!m_InstrumentCatalogs.TryGetValue(job.Product.Key, out instrumentSub))
                        {   // Failed to find a subscription.  Create a new one!
                            instrumentSub = new InstrumentCatalogSubscription(job.Product, m_Dispatcher);
                            instrumentSub.InstrumentsUpdated += InstrumentCatalog_InstrumentsUpdated;
                            instrumentSub.Start();                                                  // submit the request.
                            m_InstrumentCatalogs.Add(job.Product.Key, instrumentSub);               // store the catalog object
                            Log.NewEntry(LogLevel.Minor, "{0}: Subscribing to instr catalog for {1}.", this.Name, job.Product.Name);
                        }
                    }
                    else
                    {   // User requested Instrument info using the ProductKey and a series Name only. (Not instr Key).
                        //InstrumentLookupSubscription lookup = null;
                        Log.NewEntry(LogLevel.Major, "{0}: InstrumentLookup {1} {2}.", this.Name, job.Product, job.SeriesName);
                        InstrumentLookupSubscription subscriber = new InstrumentLookupSubscription(m_TTServices.session, m_Dispatcher, job.Product.Key, job.SeriesName);
                        subscriber.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(InstrumentLookup_InstrumentUpdated);
                        //m_InstrumentLookupsUnknown.Add(job.InstrumentKey, subscriber);
                        subscriber.Start();
                    }
                }
                else if (job.InstrumentKey != null && job.Settings == null && !job.IsTimeAndSales)
                {   //
                    // Process an Instrument information request
                    //
                    InstrumentLookupSubscription lookup = null;
                    if (!m_InstrumentLookups.TryGetValue(job.InstrumentKey, out lookup))
                    {
                        Log.NewEntry(LogLevel.Major, "{0}: InstrumentLookup {1}.", this.Name, job.InstrumentKey);
                        InstrumentLookupSubscription subscriber = new InstrumentLookupSubscription(m_TTServices.session, m_Dispatcher, job.InstrumentKey);
                        subscriber.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(InstrumentLookup_InstrumentUpdated);
                        m_InstrumentLookups.Add(job.InstrumentKey, subscriber);
                        subscriber.Start();
                    }
                    else
                    {
                        Log.NewEntry(LogLevel.Major, "{0}: InstrumentLookup {1} already submitted.", this.Name, job.InstrumentKey);
                    }
                }
                else if (job.InstrumentKey != null)
                {   //
                    // Subscribe to an instrument price
                    //
                    Instrument instrument = null;
                    InstrumentCatalogSubscription catalog       = null;                         // First, find instrument catalog for this instr.
                    InstrumentLookupSubscription  instrumentSub = null;                         // or find a specific instrument subscription.
                    //InstrumentDetails instrumentDetails = null;
                    //UVProd.InstrumentName instrumentName ;
                    if (m_InstrumentLookups.TryGetValue(job.InstrumentKey, out instrumentSub))
                    {
                        instrument = instrumentSub.Instrument;
                    }
                    else if (m_InstrumentCatalogs.TryGetValue(job.InstrumentKey.ProductKey, out catalog))
                    {
                        catalog.Instruments.TryGetValue(job.InstrumentKey, out instrument);
                    }
                    //else if (m_KeyToInstruments.TryGetValue(job.InstrumentKey, out instrumentName) && m_InstrumentDetails.TryGetValue(instrumentName, out instrumentDetails))
                    //{
                    //    m_InstrumentLookups.TryGetValue(job.InstrumentKey, out instrumentSub)
                    //}
                    else
                    {
                        Log.NewEntry(LogLevel.Minor, "{0}: I failed to find instrument key {1}.", this.Name, job.InstrumentKey.ToString());
                        return;
                    }
                    if (instrument != null)
                    {
                        if (!job.IsTimeAndSales)
                        { // this is a market data subscription request  - Subscribe or update pre-existing subscription.
                            PriceSubscription priceSub = null;
                            if (!m_PriceSubscriptions.TryGetValue(instrument.Key, out priceSub))
                            {   // Can't find a subscription, so create one.
                                Log.NewEntry(LogLevel.Major, "{0}: Creating new subscription for {1} with settings {2}.", this.Name, instrument.Name, job.Settings.PriceData);
                                priceSub = new PriceSubscription(instrument, Dispatcher.Current);
                                m_PriceSubscriptions.Add(instrument.Key, priceSub);                                      // add to our list of subscription objects.
                                if (!m_InstrKeyToVolume.ContainsKey(instrument.Key))
                                {
                                    m_InstrKeyToVolume.Add(instrument.Key, new int[4]);                                 // create a new array for volume aggregations
                                }
                                priceSub.FieldsUpdated += new FieldsUpdatedEventHandler(PriceSubscription_Updated);     // attach my handler to it.
                                priceSub.Settings       = job.Settings;
                                priceSub.Start();
                            }
                            else
                            {
                                Log.NewEntry(LogLevel.Major, "{0}: Found old subscription for {1}.  Overwriting settings {2}.", this.Name, instrument.Name, job.Settings.ToString());
                                priceSub.Settings = job.Settings;
                                priceSub.Start();
                            }
                        }
                        else
                        { // this is a time and sales data request
                            TimeAndSalesSubscription timeAndSalesSub = null;
                            if (!m_TimeAndSalesSubscriptions.TryGetValue(instrument.Key, out timeAndSalesSub))
                            {   // Can't find a subscription, so create one.
                                Log.NewEntry(LogLevel.Major, "{0}: Creating new time and sales subscription for {1}", this.Name, instrument.Name);
                                timeAndSalesSub = new TimeAndSalesSubscription(instrument, Dispatcher.Current);
                                m_TimeAndSalesSubscriptions.Add(instrument.Key, timeAndSalesSub);                       // add to our list of subscription objects.
                                if (!m_InstrKeyToVolume.ContainsKey(instrument.Key))
                                {
                                    m_InstrKeyToVolume.Add(instrument.Key, new int[4]);                                               // create a new array for volume aggregations
                                }
                                timeAndSalesSub.Update += new EventHandler <TimeAndSalesEventArgs>(TimeAndSalesSubscription_Updated); // attach my handler to it.
                                timeAndSalesSub.Start();
                            }
                            else
                            {
                                Log.NewEntry(LogLevel.Major, "{0}: Found existing time and sales subscription for {1}.", this.Name, instrument.Name, job.Settings.ToString());
                            }
                        }
                    }
                }
            } //wend Job in WorkQueue.
        }     //ProcessAJob()
        public void req_Update(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.Instrument != null && e.Error == null)
            {
                // Create a TradeSubscription with an Instrument filter
                ts = new TradeSubscription(apiInstance.Session, Dispatcher.Current);

                TradeSubscriptionInstrumentFilter tsIF =
                       new TradeSubscriptionInstrumentFilter(apiInstance.Session, e.Instrument.Key, false, "instr");

                ts.SetFilter(tsIF);
                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();

                // Subscribe for Inside Market Data
                ps = new PriceSubscription(e.Instrument, Dispatcher.Current);
                ps.Settings = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
                ps.FieldsUpdated += new FieldsUpdatedEventHandler(priceSub_FieldsUpdated);
                ps.Start();
            }
            else if (e.IsFinal)
            {
                // Instrument was not found and TT API has given up looking for it
                Console.WriteLine("Cannot find instrument: " + e.Error.Message);
                Dispose();
            }
        }
        /// <summary>
        /// Create a price subscription and assign it to the InstrumentModel
        /// </summary>
        /// <param name="instrument">Instrument to subscribe to</param>
        private void CreatePriceSubscription(Instrument instrument)
        {
            // Create a Price Subscription, this should be called from a worker thread
            // Dispatcher.Current could be used in place of m_BindingModels[instrument.Key].Dispatcher
            // because the current thread should have the correct dispatcher at this point.
            PriceSubscription priceSubscription = new PriceSubscription(instrument, m_bindingModels[instrument.Key].Dispatcher);
            m_bindingModels[instrument.Key].Subscription = priceSubscription;

            priceSubscription = new PriceSubscription(instrument, m_bindingModels[instrument.Key].Dispatcher);
            priceSubscription.Settings = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
            priceSubscription.FieldsUpdated += new FieldsUpdatedEventHandler(priceSubscription_FieldsUpdated);
            priceSubscription.Start();
        }
        /// <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;
                }

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

            // only run shutdown once
            m_shutdownInProcess = true;
        }