示例#1
0
 private void SuscribeToProductCatalogue(Market market)
 {
     log.Info($"Suscribe to market: {market.Name}");
     _prodCat = market.CreateProductCatalogSubscription(Dispatcher.Current);
     _prodCat.ProductsUpdated += ProductsUpdated;
     _prodCat.Start();
 }
示例#2
0
        /// <summary>
        /// Dispose of all the TT API objects and shutdown the TT API
        /// </summary>
        public void shutdownTTAPI()
        {
            if (!m_shutdownInProcess)
            {
                // Dispose may be called on another thread due to garbage collection.
                // InvokeIfRequired is an extension method defined in Utility.cs within this project.
                // Please refer to Utility.cs for more information on what InvokeIfRequired is doing.
                Dispatcher.Current.InvokeIfRequired(() =>
                {
                    if (m_prodCat != null)
                    {
                        m_prodCat.ProductsUpdated -= new EventHandler <ProductCatalogUpdatedEventArgs>(productsUpdated);
                        m_prodCat.Dispose();
                        m_prodCat = null;
                    }

                    if (m_instrumentCatalogSubscriptionList.Count > 0)
                    {
                        foreach (InstrumentCatalogSubscription instrCat in m_instrumentCatalogSubscriptionList.Values)
                        {
                            instrCat.InstrumentsUpdated -= new EventHandler <InstrumentCatalogUpdatedEventArgs>(instrumentsUpdated);
                            instrCat.Dispose();
                        }
                        m_instrumentCatalogSubscriptionList.Clear();
                    }

                    foreach (MarketListViewItem market in m_marketList)
                    {
                        market.Dispose();
                    }
                    m_marketList.Clear();

                    foreach (MarketListViewItem market in listViewMarketList.Items)
                    {
                        market.Dispose();
                    }
                    listViewMarketList.Items.Clear();

                    foreach (FeedListViewItem feed in m_feedList)
                    {
                        feed.Dispose();
                    }
                    m_feedList.Clear();

                    foreach (FeedListViewItem feed in listViewMarketFeeds.Items)
                    {
                        feed.Dispose();
                    }
                    listViewMarketFeeds.Items.Clear();
                });

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

            // only run shutdown once
            m_shutdownInProcess = true;
        }
示例#3
0
        /// <summary>
        /// ProductCatalogSubscription ProductsUpdated event.
        /// This will update the product list in the product TreeView.
        /// </summary>
        /// <param name="sender">ProductCatalogSubscription</param>
        /// <param name="e">ProductCatalogUpdatedEventArgs</param>
        private void productsUpdated(object sender, ProductCatalogUpdatedEventArgs e)
        {
            var sub = (ProductCatalogSubscription)sender;

            List <ProductType>    selectedTypes = BuildSelectedTypes();
            IEnumerable <Product> products;

            treeViewProductList.Nodes.Clear();

            // If a search filter is set filter the product list by that filter.
            // If no search filter is set list all products for the selected market.
            if (String.IsNullOrEmpty(m_searchFilter))
            {
                // Please refer to MSDN for more information about Lambda expressions used to Query collections. http://msdn.microsoft.com/en-us/library/bb397675
                products = from Product product in sub.Products.Values
                           join type in selectedTypes on product.Type equals type
                           orderby product.Name
                           select product;
            }
            else
            {
                // Please refer to MSDN for more information about Lambda expressions used to Query collections. http://msdn.microsoft.com/en-us/library/bb397675
                products = from Product product in sub.Products.Values
                           join type in selectedTypes on product.Type equals type
                           where product.Name.Contains(m_searchFilter)
                           orderby product.Name
                           select product;
            }

            // Add product nodes to the TreeView.
            // Set the default child node as "loading..." This node will be replaced when the node is expanded and
            // the instrument catalog is downloaded for the given product.
            foreach (Product product in products)
            {
                TreeNode prodNode = treeViewProductList.Nodes.Add(product.Name);
                prodNode.Tag = (object)product;
                prodNode.SelectedImageIndex = prodNode.ImageIndex = GetImageCode(product.Type);

                TreeNode childNode = new TreeNode("Loading ...", GetImageCode(product.Type), GetImageCode(product.Type));
                prodNode.Nodes.Add(childNode);
            }

            // Clean up this ProductCatalog subscription.
            if (m_prodCat != null)
            {
                m_prodCat.ProductsUpdated -= new EventHandler <ProductCatalogUpdatedEventArgs>(productsUpdated);
                m_prodCat.Dispose();
                m_prodCat = null;
            }

            toolStripStatusLabel.Text = "There are " + Convert.ToString(products.Count()) + " products";
            Cursor = Cursors.Default;
        }
        public void CreateMarketSubscription()
        {
            if (_dispatcher.InvokeRequired())
            {
                _dispatcher.BeginInvoke(() =>
                {
                    CreateMarketSubscription();
                });
                return;
            }

            Dispatcher dispatcher = Dispatcher.Current;

            Console.WriteLine("Creating MarketSubscription...");

            // Find each market and subscribe to products for that market
            foreach (MarketKey key in _apiSession.MarketCatalog.Markets.Keys)
            {
                Market market = _apiSession.MarketCatalog.Markets[key];
                currentMarkets.Add(key, market);
                ProductCatalogSubscription pcs = market.CreateProductCatalogSubscription(Dispatcher.Current);
                pcs.ProductsUpdated += new EventHandler <ProductCatalogUpdatedEventArgs>(pcs_ProductsUpdated);
                pcs.Start();
            }

            // Find all the fill feeds, order feeds, price feeds and localAutospreader order feed
            foreach (FillFeed feed in _apiSession.MarketCatalog.FillFeeds)
            {
                currentFillFeeds.Add(feed);
            }
            localAutospreaderOrderFeed = _apiSession.MarketCatalog.LocalAutospreaderEngineOrderFeed;
            foreach (OrderFeed feed in _apiSession.MarketCatalog.OrderFeeds)
            {
                currentOrderFeeds.Add(feed);
            }
            foreach (PriceFeed feed in _apiSession.MarketCatalog.PriceFeeds)
            {
                currentPriceFeeds.Add(feed);
            }

            // Subscribe to some events related to markets
            _apiSession.MarketCatalog.FeedStatusChanged     += new EventHandler <FeedStatusChangedEventArgs>(MarketCatalog_FeedStatusChanged);
            _apiSession.MarketCatalog.MarketsUpdated        += new EventHandler <MarketCatalogUpdatedEventArgs>(MarketCatalog_MarketsUpdated);
            _apiSession.MarketCatalog.TradingEnabledChanged += new EventHandler <TradingEnabledChangedEventArgs>(MarketCatalog_TradingEnabledChanged);

            Console.WriteLine("MarketSubscription created.");
        }
示例#5
0
        /// <summary>
        /// SelectedIndexChanged event from the product ListView window.
        /// This event fires when the user changes the selected product.
        /// </summary>
        private void listViewProductTypeList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listViewMarketList.SelectedItems.Count > 0)
            {
                Cursor = Cursors.WaitCursor;
                Market market = listViewMarketList.SelectedItems[0].Tag as Market;

                if (m_prodCat != null)
                {
                    m_prodCat.ProductsUpdated -= productsUpdated;
                    m_prodCat.Dispose();
                    m_prodCat = null;
                }

                // Create the market subscription.
                createProductSubscription(market);
            }
        }
        /// <summary>
        /// SelectedIndexChanged event from the product ListView window.
        /// This event fires when the user changes the selected product.
        /// </summary>
        private void listViewProductTypeList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listViewMarketList.SelectedItems.Count > 0)
            {
                Cursor = Cursors.WaitCursor;
                Market market = listViewMarketList.SelectedItems[0].Tag as Market;

                if (m_prodCat != null)
                {
                    m_prodCat.ProductsUpdated -= productsUpdated;
                    m_prodCat.Dispose();
                    m_prodCat = null;
                }

                // Create the market subscription.
                createProductSubscription(market);
            }
        }
        /// <summary>
        /// ProductCatalogSubscription ProductsUpdated event.
        /// This will update the product list in the product TreeView.
        /// </summary>
        /// <param name="sender">ProductCatalogSubscription</param>
        /// <param name="e">ProductCatalogUpdatedEventArgs</param>
        private void productsUpdated(object sender, ProductCatalogUpdatedEventArgs e)
        {
            var sub = (ProductCatalogSubscription)sender;

            List<ProductType> selectedTypes = BuildSelectedTypes();
            IEnumerable<Product> products;
            treeViewProductList.Nodes.Clear();

            // If a search filter is set filter the product list by that filter.
            // If no search filter is set list all products for the selected market.
            if (String.IsNullOrEmpty(m_searchFilter))
            {
                // Please refer to MSDN for more information about Lambda expressions used to Query collections. http://msdn.microsoft.com/en-us/library/bb397675
                products = from Product product in sub.Products.Values
                           join type in selectedTypes on product.Type equals type
                           orderby product.Name
                           select product;
            }
            else
            {
                // Please refer to MSDN for more information about Lambda expressions used to Query collections. http://msdn.microsoft.com/en-us/library/bb397675
                products = from Product product in sub.Products.Values
                           join type in selectedTypes on product.Type equals type
                           where product.Name.Contains(m_searchFilter)
                           orderby product.Name
                           select product;
            }

            // Add product nodes to the TreeView.
            // Set the default child node as "loading..." This node will be replaced when the node is expanded and
            // the instrument catalog is downloaded for the given product.
            foreach (Product product in products)
            {
                TreeNode prodNode = treeViewProductList.Nodes.Add(product.Name);
                prodNode.Tag = (object)product;
                prodNode.SelectedImageIndex = prodNode.ImageIndex = GetImageCode(product.Type);

                TreeNode childNode = new TreeNode("Loading ...", GetImageCode(product.Type), GetImageCode(product.Type));
                prodNode.Nodes.Add(childNode);
            }

            // Clean up this ProductCatalog subscription.
            if (m_prodCat != null)
            {
                m_prodCat.ProductsUpdated -= new EventHandler<ProductCatalogUpdatedEventArgs>(productsUpdated);
                m_prodCat.Dispose();
                m_prodCat = null;
            }

            toolStripStatusLabel.Text = "There are " + Convert.ToString(products.Count()) + " products";
            Cursor = Cursors.Default;
        }
 /// <summary>
 /// Create a ProductCatalogSubscription.
 /// </summary>
 /// <param name="market">Market to create subscription.</param>
 private void createProductSubscription(Market market)
 {
     m_prodCat = market.CreateProductCatalogSubscription(Dispatcher.Current);
     m_prodCat.ProductsUpdated += new EventHandler<ProductCatalogUpdatedEventArgs>(productsUpdated);
     m_prodCat.Start();
 }
        /// <summary>
        /// Dispose of all the TT API objects and shutdown the TT API 
        /// </summary>
        public void shutdownTTAPI()
        {
            if (!m_shutdownInProcess)
            {
                // Dispose may be called on another thread due to garbage collection.
                // InvokeIfRequired is an extension method defined in Utility.cs within this project.
                // Please refer to Utility.cs for more information on what InvokeIfRequired is doing.
                Dispatcher.Current.InvokeIfRequired(() =>
                {
                    if (m_prodCat != null)
                    {
                        m_prodCat.ProductsUpdated -= new EventHandler<ProductCatalogUpdatedEventArgs>(productsUpdated);
                        m_prodCat.Dispose();
                        m_prodCat = null;
                    }

                    if (m_instrumentCatalogSubscriptionList.Count > 0)
                    {
                        foreach (InstrumentCatalogSubscription instrCat in m_instrumentCatalogSubscriptionList.Values)
                        {
                            instrCat.InstrumentsUpdated -= new EventHandler<InstrumentCatalogUpdatedEventArgs>(instrumentsUpdated);
                            instrCat.Dispose();
                        }
                        m_instrumentCatalogSubscriptionList.Clear();
                    }

                    foreach (MarketListViewItem market in m_marketList)
                    {
                        market.Dispose();
                    }
                    m_marketList.Clear();

                    foreach (MarketListViewItem market in listViewMarketList.Items)
                    {
                        market.Dispose();
                    }
                    listViewMarketList.Items.Clear();

                    foreach (FeedListViewItem feed in m_feedList)
                    {
                        feed.Dispose();
                    }
                    m_feedList.Clear();

                    foreach (FeedListViewItem feed in listViewMarketFeeds.Items)
                    {
                        feed.Dispose();
                    }
                    listViewMarketFeeds.Items.Clear();
                });

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

            // only run shutdown once
            m_shutdownInProcess = true;
        }
示例#10
0
 /// <summary>
 /// Create a ProductCatalogSubscription.
 /// </summary>
 /// <param name="market">Market to create subscription.</param>
 private void createProductSubscription(Market market)
 {
     m_prodCat = market.CreateProductCatalogSubscription(Dispatcher.Current);
     m_prodCat.ProductsUpdated += new EventHandler <ProductCatalogUpdatedEventArgs>(productsUpdated);
     m_prodCat.Start();
 }
        /// <summary>
        /// Cleanup subscriptions before shutting down.
        /// </summary>
        private void Cleanup()
        {
            // Dispose may be called on another thread due to garbage collection.
            // InvokeIfRequired is an extension method defined in Utility.cs within this project.
            // Please refer to Utility.cs for more information on what InvokeIfRequired is doing.
            m_dispatcher.InvokeIfRequired(() =>
            {
                if (m_prodCat != null)
                {
                    m_prodCat.ProductsUpdated -= new EventHandler<ProductCatalogUpdatedEventArgs>(productsUpdated);
                    m_prodCat.Dispose();
                    m_prodCat = null;
                }

                if (m_instrumentCatalogSubscriptionList.Count > 0)
                {
                    foreach (InstrumentCatalogSubscription instrCat in m_instrumentCatalogSubscriptionList.Values)
                    {
                        instrCat.InstrumentsUpdated -= new EventHandler<InstrumentCatalogUpdatedEventArgs>(instrumentsUpdated);
                        instrCat.Dispose();
                    }
                    m_instrumentCatalogSubscriptionList.Clear();
                }

                foreach (MarketListViewItem market in m_marketList)
                {
                    market.Dispose();
                }
                m_marketList.Clear();

                foreach (MarketListViewItem market in listViewMarketList.Items)
                {
                    market.Dispose();
                }
                listViewMarketList.Items.Clear();

                foreach (FeedListViewItem feed in m_feedList)
                {
                    feed.Dispose();
                }
                m_feedList.Clear();

                foreach (FeedListViewItem feed in listViewMarketFeeds.Items)
                {
                    feed.Dispose();
                }
                listViewMarketFeeds.Items.Clear();

                // Shutdown the TT API instance.
                m_apiInstance.Shutdown();
            });
        }
示例#12
0
        }//HubEventHandler()

        //
        //
        //
        //
        // *************************************************************************
        // ****                 Process Market Hub Requests()                   ****
        // *************************************************************************
        /// <summary>
        /// This processes requests from the user.
        /// This is called by the hub thread.
        /// </summary>
        private void ProcessHubRequestProducts(Misty.Lib.MarketHubs.MarketHubRequest request)
        {
            Market market = null;
            IDictionary <MarketKey, Market> marketList = null;
            List <string> marketNameList = new List <string>();       // Collect all markets we are interested in.

            foreach (object o in request.Data)
            {
                string marketName = null;
                if (o is Misty.Lib.Products.Product)
                {
                    marketName = ((Misty.Lib.Products.Product)o).ServerName; // user gave us product objects.
                }
                else if (o is string)
                {
                    marketName = (string)o;                        // user gave us strings (which must be server names)
                }
                if (!string.IsNullOrEmpty(marketName) && !marketNameList.Contains(marketName))
                {
                    marketNameList.Add(marketName);
                }
            }
            marketList = m_TTService.session.MarketCatalog.Markets;             // markets we know
            foreach (string marketName in marketNameList)                       // search for match of name to given by user.
            {
                market = null;
                foreach (Market mkt in marketList.Values)                       // search for mkt with correct name.
                {
                    if (mkt.Name.Equals(marketName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        market = mkt;
                        break;
                    }
                }
                //
                if (market != null)
                {   // We found a recognized market.
                    ProductCatalogSubscription productCatalog = null;
                    if (m_ProductCatalogSubscriptionList.TryGetValue(market, out productCatalog))
                    {   // We have already subscribed to these products, so fire our current list of known products.
                        // As more arrive we will fire another event.
                        List <Misty.Lib.Products.Product> productList = new List <Misty.Lib.Products.Product>();
                        lock (m_ProductMapLock)
                        {
                            foreach (Misty.Lib.Products.Product prod in m_ProductMap.Keys)      // search thru product list created during TT callbacks.
                            {
                                if (prod.ServerName.Equals(market.Name))
                                {
                                    productList.Add(prod);
                                }
                            }
                        }
                        OnMarketFoundResource(productList);                              // trigger event for subscribers
                    }
                    else
                    {   // Create new product catalog subscription for this market.
                        productCatalog = market.CreateProductCatalogSubscription(m_TTService.m_Dispatcher);
                        productCatalog.ProductsUpdated += new EventHandler <ProductCatalogUpdatedEventArgs>(ProductCatalog_Updated);
                        productCatalog.Start();
                        m_ProductCatalogSubscriptionList.Add(market, productCatalog);
                        Log.NewEntry(LogLevel.Minor, "ProcessMarketHubRequests: Created new ProductCatalog subscription service for {0}.  Have {1} in total.", market.Name, m_ProductCatalogSubscriptionList.Count);
                    }
                }
                else
                {
                    Log.NewEntry(LogLevel.Error, "ProcessMarketHubRequests: Failed to find market {0}.", marketName);
                }
            }
        }// ProcessHubRequestProducts().