예제 #1
0
        }     //ProcessHubRequestInstruments()

        //
        //
        //
        // *************************************************************************
        // ****                 Process Hub Request Instruments()               ****
        // *************************************************************************
        private void ProcessHubRequestInstrumentPrice(Misty.Lib.MarketHubs.MarketHubRequest request)
        {
            if (request.Data == null || request.Data.Count < 1)
            {
                return;
            }
            foreach (object dataObj in request.Data)
            {
                Type dataType = dataObj.GetType();
                if (dataType == typeof(InstrumentName))
                {
                    InstrumentName    instr = (InstrumentName)dataObj;
                    InstrumentDetails details;
                    lock (m_InstrumentLock)
                    {
                        if (m_InstrumentDetails.TryGetValue(instr, out details))
                        {     // found desired instrument.
                            if (m_InstrumentMarkets.ContainsKey(instr))
                            { // We have already subscribed to this instrument.
                                Log.NewEntry(LogLevel.Minor, "ProcessHubRequestInstrumentPrice: We already have a subscription to {0}. Ignore request {1}.", instr.SeriesName, request.ToString());
                            }
                            else
                            {                            // We do not have a subscription to this instrument.
                                TryCreateNewBook(instr); // m_InstrumentDetails[instr].Key.MarketKey.Name);
                                m_PriceListener.SubscribeTo(details.Key, new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket));
                            }
                        }
                        else
                        {   // The user has not previously request info about this Product family.
                            //Log.NewEntry(LogLevel.Warning, "ProcessHubRequestInstrumentPrice: Failed to locate TT version of {0} for request {1}.", instr.SeriesName, request.ToString());
                        }
                    }
                }
                else if (dataType == typeof(InstrumentKey))
                {
                    InstrumentKey instrKey = (InstrumentKey)dataObj;
                    lock (m_InstrumentLock)
                    {
                        bool           isFoundInstrument = false;
                        InstrumentName instrName         = new MistyProds.InstrumentName();
                        foreach (InstrumentName i in m_InstrumentDetails.Keys)
                        {
                            if (m_InstrumentDetails[i].Key.Equals(instrKey))
                            {
                                instrName         = i;
                                isFoundInstrument = true;
                                break;
                            }
                        }
                        if (!isFoundInstrument)
                        {   // Unknown instrument.
                            Log.NewEntry(LogLevel.Warning, "ProcessHubRequestInstrumentPrice: Price subscription request with unknown instrKey = {0}", instrKey.ToString());
                        }
                        else
                        {   // We actually know this instrument.
                            if (!m_InstrumentMarkets.ContainsKey(instrName))
                            {
                                TryCreateNewBook(instrName);     //, m_InstrumentDetails[instrName].Key.MarketKey.Name);
                                m_PriceListener.SubscribeTo(instrKey, new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket));
                            }
                        }
                    }
                }
                else
                {
                    Log.NewEntry(LogLevel.Warning, "ProcessHubRequestInstrumentPrice: Failed to recognize data object {0} for request {1}.", dataType.Name, request.ToString());
                }
            } //next data
        }     // ProcessHubRequestInstrumentPrice()
예제 #2
0
        }// ProcessHubRequestProducts().

        //
        //
        // *************************************************************************
        // ****                 Process Hub Request Instruments()               ****
        // *************************************************************************
        /// <summary>
        /// Process users request for a list of Misty Instruments associated with a collection
        /// of user-provided Misty Products.
        /// </summary>
        private void ProcessHubRequestInstruments(Misty.Lib.MarketHubs.MarketHubRequest request)
        {
            if (request.Data == null || request.Data.Count < 1)
            {
                return;
            }
            foreach (object o in request.Data)
            {
                Type dataType = o.GetType();
                if (dataType == typeof(Misty.Lib.Products.Product))
                {   // User has provided a Product object.
                    Misty.Lib.Products.Product mistyProduct = (Misty.Lib.Products.Product)o;
                    Product ttProduct = null;
                    lock (m_ProductMapLock)
                    {
                        ProductKey productKey;
                        if (m_ProductMap.TryGetValue(mistyProduct, out productKey))
                        {
                            ttProduct = m_Products[productKey];
                        }
                    }
                    if (ttProduct != null)
                    {
                        m_PriceListener.SubscribeTo(ttProduct);                     // we have this product in our lists.
                    }
                    else
                    {   // User has given us a one-off specific product.
                        Log.NewEntry(LogLevel.Warning, "ProcessHubRequestInstruments: Failed to find Product {0}.", mistyProduct.ToString());
                    }
                }
                else if (dataType == typeof(InstrumentName))
                {
                    InstrumentName    instrumentName = (InstrumentName)o;
                    InstrumentDetails details;
                    lock (m_InstrumentLock)
                    {
                        if (!m_InstrumentDetails.TryGetValue(instrumentName, out details))
                        {   // Could not find desired instrument in our list of details. Try to request it.
                        }
                    }
                }
                else if (dataType == typeof(InstrumentKey))
                {
                    InstrumentKey instrKey = (InstrumentKey)o;
                    lock (m_InstrumentLock)
                    {
                        bool isFound = false;
                        foreach (InstrumentDetails detail in m_InstrumentDetails.Values)
                        {
                            if (detail.Key == instrKey)
                            {
                                isFound = true;
                                break;
                            }
                        }
                        if (!isFound)
                        {
                            m_PriceListener.SubscribeTo(instrKey);
                        }
                    }
                }
                else
                {
                    Log.NewEntry(LogLevel.Warning, "ProcessHubRequestInstruments: Failed to recognize type of Data {0} in {1}.", dataType.Name, request.ToString());
                }
            } //next data
        }     //ProcessHubRequestInstruments()