示例#1
0
        public void startTradeSubscriptions(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.Instrument != null && e.Error == null)
            {
                // Create a TradeSubscription to listen for order / fill events only for orders submitted through it
                ts = new InstrumentTradeSubscription(m_apiInstance.Session, Dispatcher.Current, e.Instrument, true, true, false, false);
                ts.OrderUpdated += new EventHandler <OrderUpdatedEventArgs>(m_ts_OrderUpdated);
                ts.OrderAdded   += new EventHandler <OrderAddedEventArgs>(m_ts_OrderAdded);
                ts.OrderDeleted += new EventHandler <OrderDeletedEventArgs>(m_ts_OrderDeleted);

                if (orderFilledEventHandler != null)
                {
                    ts.OrderFilled += new EventHandler <OrderFilledEventArgs>(orderFilledEventHandler);
                }

                ts.OrderRejected += new EventHandler <OrderRejectedEventArgs>(m_ts_OrderRejected);

                TsDictionary.Add(e.Instrument.Key, ts);
                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>
        /// 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>
        /// 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;
        }
示例#4
0
        /// <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);

                    // populate the order feed dropdown
                    this.cboOrderFeed.Items.Clear();
                    foreach (OrderFeed orderFeed in e.Instrument.GetValidOrderFeeds())
                    {
                        this.cboOrderFeed.Items.Add(orderFeed);
                    }

                    this.cboOrderFeed.SelectedIndex = 0;

                    // This sample will monitor new orders and deleting working orders
                    CreateInstrumentTradeSubscription(e.Instrument);
                    m_instrumentTradeSubscription.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>
        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);
            }
        }
示例#6
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;
            }
        }
示例#7
0
        /// <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_instrumentTradeSubscription != null)
                    {
                        m_instrumentTradeSubscription.Dispose();
                        m_instrumentTradeSubscription = null;
                    }

                    // The use of the InstrumentTradeSubscription will filter for a specific instrument
                    m_instrumentTradeSubscription                    = new InstrumentTradeSubscription(m_TTAPI.Session, Dispatcher.Current, e.Instrument);
                    m_instrumentTradeSubscription.EnablePNL          = true;
                    m_instrumentTradeSubscription.ProfitLossChanged += new EventHandler <ProfitLossChangedEventArgs>(instrumentTradeSubscription_ProfitLossChanged);
                    m_instrumentTradeSubscription.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));
            }
        }
示例#8
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);
        }
示例#9
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);
            }
        }
示例#10
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();
            }
        }
示例#11
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);
            }
        }
        /// <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>
        /// 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>
        /// 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_InstrumentTradeSubscription != null)
                    {
                        m_InstrumentTradeSubscription.Dispose();
                        m_InstrumentTradeSubscription = null;
                    }

                    // populate the order feed dropdown
                    this.cboOrderFeed.Items.Clear();
                    foreach (OrderFeed orderFeed in e.Instrument.GetValidOrderFeeds())
                        this.cboOrderFeed.Items.Add(orderFeed);

                    this.cboOrderFeed.SelectedIndex = 0;

                    // This sample will monitor new orders and deleting working orders
                    m_InstrumentTradeSubscription = new InstrumentTradeSubscription(m_TTAPI.Session, Dispatcher.Current, e.Instrument);
                    m_InstrumentTradeSubscription.OrderAdded += new EventHandler<OrderAddedEventArgs>(instrumentTradeSubscription_OrderAdded);
                    m_InstrumentTradeSubscription.OrderDeleted += new EventHandler<OrderDeletedEventArgs>(instrumentTradeSubscription_OrderDeleted);
                    m_InstrumentTradeSubscription.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));
            }
        }
        /// <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_instrumentTradeSubscription != null)
                    {
                        m_instrumentTradeSubscription.Dispose();
                        m_instrumentTradeSubscription = null;
                    }

                    // The use of the InstrumentTradeSubscription will filter for a specific instrument
                    m_instrumentTradeSubscription = new InstrumentTradeSubscription(m_TTAPI.Session, Dispatcher.Current, e.Instrument);
                    m_instrumentTradeSubscription.EnablePNL = true;
                    m_instrumentTradeSubscription.ProfitLossChanged += new EventHandler<ProfitLossChangedEventArgs>(instrumentTradeSubscription_ProfitLossChanged);
                    m_instrumentTradeSubscription.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));
            }
        }
示例#16
0
        public void startTradeSubscriptions(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.Instrument != null && e.Error == null)
            {
                // Create a TradeSubscription to listen for order / fill events only for orders submitted through it
                ts = new InstrumentTradeSubscription(m_apiInstance.Session, Dispatcher.Current, e.Instrument, true, true, false, false);
                ts.OrderUpdated += new EventHandler<OrderUpdatedEventArgs>(m_ts_OrderUpdated);
                ts.OrderAdded += new EventHandler<OrderAddedEventArgs>(m_ts_OrderAdded);
                ts.OrderDeleted += new EventHandler<OrderDeletedEventArgs>(m_ts_OrderDeleted);

                if (orderFilledEventHandler !=null)
                {
                    ts.OrderFilled += new EventHandler<OrderFilledEventArgs>(orderFilledEventHandler);
                }
               
                ts.OrderRejected += new EventHandler<OrderRejectedEventArgs>(m_ts_OrderRejected);

                TsDictionary.Add(e.Instrument.Key,ts);
                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();
            }
        }