Beispiel #1
0
 private void SuscribeToProductCatalogue(Market market)
 {
     log.Info($"Suscribe to market: {market.Name}");
     _prodCat = market.CreateProductCatalogSubscription(Dispatcher.Current);
     _prodCat.ProductsUpdated += ProductsUpdated;
     _prodCat.Start();
 }
        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.");
        }
Beispiel #3
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>
 /// 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();
 }
        }//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().