Example #1
0
        }     //TryGetInstrument()

        //
        // *****************************************************************
        // ****                 Try Get Product()                       ****
        // *****************************************************************
        /// <summary>
        /// This is a thread-safe way to query the Market whether it knows the Misty Product
        /// associated with a particular TT ProductKey.
        /// </summary>
        public bool TryLookupProduct(ProductKey ttProductKey, out Misty.Lib.Products.Product product)
        {
            bool isGood = false;

            lock (m_ProductMapLock)
            {
                if (m_ProductMapKey.TryGetValue(ttProductKey, out product))
                {
                    isGood = true;
                }
            } //lock
            return(isGood);
        }     //TryGetProduct()
        }         // ReadStatements()

        //
        //
        //
        // *****************************************************************
        // ****                 Create InstrumentName()                 ****
        // *****************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <param name="typeCodeStr"></param>
        /// <param name="instrDescStr"></param>
        /// <param name="instrSymbolStr"></param>
        /// <param name="rcgProduct"></param>
        /// <param name="rcgInstrumentName"></param>
        /// <returns></returns>
        private bool TryCreateInstrumentName(string typeCodeStr, string instrDescStr, string instrSymbolStr, out Misty.Lib.Products.Product rcgProduct, out Misty.Lib.Products.InstrumentName rcgInstrumentName)
        {
            int n;

            if (typeCodeStr.Contains("O") || typeCodeStr.Contains("C") || typeCodeStr.Contains("P"))
            {
                ProductTypes mistyProductType = ProductTypes.Option;
                string       exchStr          = "Option";
                string       instrStr         = instrDescStr;
                string       seriesName       = instrDescStr;
                rcgProduct        = new Product(exchStr, instrStr, mistyProductType);
                rcgInstrumentName = new InstrumentName(rcgProduct, seriesName);
            }
            else if (string.IsNullOrEmpty(typeCodeStr) || typeCodeStr.Contains("F"))
            {   // futures format = "DEC 13 TOCOM GOLD"
                ProductTypes mistyProductType = ProductTypes.Future;
                string[]     elements;
                try
                {
                    elements = instrDescStr.Split(DelimSpace, StringSplitOptions.RemoveEmptyEntries);
                    int nextPtr = 0;
                    //
                    // Instrument date extraction
                    //
                    string seriesName;
                    if (Int32.TryParse(elements[0], out n))
                    {                                                                                                         // Seems to be "dd MMM yy" format, since first element is integer n = "dd"
                        string s         = elements[1].Trim();                                                                // extract month part
                        string monthName = string.Format("{0}{1}", s.Substring(0, 1).ToUpper(), s.Substring(1, 2).ToLower()); // MAY --> May
                        seriesName = string.Format("{0:00}{1}{2}", n, monthName, elements[2].Trim());                         // 08May13 for example
                        seriesName = "CA 3M";
                        nextPtr    = 3;                                                                                       // ptr to next element.
                    }
                    else
                    {                                                                                                         // Seems to be "MMM yy" format
                        string s         = elements[0].Trim();                                                                // extract month part
                        string monthName = string.Format("{0}{1}", s.Substring(0, 1).ToUpper(), s.Substring(1, 2).ToLower()); // MAY --> May
                        seriesName = string.Format("{0}{1}", monthName, elements[1].Trim());
                        nextPtr    = 2;                                                                                       // ptr to next element.
                    }
                    string exchStr;
                    string instrStr;
                    int    remainingElements = elements.Length - nextPtr;
                    if (remainingElements == 1)
                    {   // No obvious delineation between product and exch?
                        // Assume a 3-character exchange code!  I believe RCG uses fixed length fields...
                        string s = elements[nextPtr].Trim();
                        exchStr  = s.Substring(0, 3);               // First 3 chars
                        instrStr = s.Substring(3);                  // remaining symbol
                        nextPtr++;
                    }
                    else
                    {
                        exchStr = elements[nextPtr].Trim();         // presume exch name is ONE-word long
                        nextPtr++;
                        instrStr = elements[nextPtr].Trim();
                        nextPtr++;
                        while (nextPtr < elements.Length)
                        {
                            instrStr = string.Format("{0} {1}", instrStr, elements[nextPtr].Trim());
                            nextPtr++;
                        }
                    }
                    rcgProduct        = new Product(exchStr, instrStr, mistyProductType);
                    rcgInstrumentName = new InstrumentName(rcgProduct, seriesName);
                }
                catch (Exception)
                {
                    // TODO: Write error message to log, and continue.
                    rcgProduct        = new Product();
                    rcgInstrumentName = new InstrumentName();
                    return(false);
                }
            }
            else
            {
                rcgProduct        = new Product();
                rcgInstrumentName = new InstrumentName();
            }
            // Exit
            return(true);
        }// CreateInstrumentName()
Example #3
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()