예제 #1
0
        public bool FindTicker(string[] lineParts, out CMETickerInfo ticker,
                               out CMEBulletinReference reference, string section)
        {
            ticker    = null;
            reference = null;

            var title = string.Join(" ", lineParts);

            foreach (var tick in tickers)
            {
                foreach (var tickRef in tick.bulletinReferences)
                {
                    if (tickRef.Section == section && tickRef.Title == title)
                    {
                        ticker    = tick;
                        reference = tickRef;
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #2
0
        private bool ParseTxtDocument(string fileName, CMETickerInfoCollection bulletinInfo)
        {
            // получить секцию из имени файла
            int sectionNum;

            if (!GetSectionNumFromFileName(fileName, out sectionNum))
            {
                return(false);
            }
            SectionNum = sectionNum.ToString();

            // получить набор таблиц (экспирация - опцион - тип опциона)
            CMEBulletinTable curTable      = null;
            bool             docDateParsed = false;

            CMETickerInfo        curTicker    = null;
            CMEBulletinReference curTickerRef = null;

            using (var sr = new StreamReader(fileName, Encoding.Unicode))
            {
                while (!sr.EndOfStream)
                {
                    // парсинг даты
                    var line = sr.ReadLine();
                    try
                    {
                        if (!docDateParsed)
                        {
                            docDateParsed = IsDateRow(line);
                            continue;
                        }

                        // строка содержит месяц экспирации?
                        line = line.Trim(' ', (char)9);
                        var parts = line.Split(new[] { ' ', (char)9 }, StringSplitOptions.RemoveEmptyEntries);
                        if (parts.Length == 0)
                        {
                            continue;
                        }
                        var em = ExpirationMonth.Parse(parts[0]);
                        if (em != null)
                        {
                            if (curTicker != null && curTickerRef != null)
                            {
                                // создать таблицу
                                if (curTable != null)
                                {
                                    tables.Add(curTable);
                                }
                                curTable = new CMEBulletinTable
                                {
                                    ExpMonth           = em,
                                    OptStyle           = curTickerRef.OptionStyle,
                                    OptType            = curTickerRef.OptionType,
                                    SpotSymbol         = curTicker.SpotSymbol,
                                    StrikeToBaseRatio  = curTicker.StrikeToBaseRatio,
                                    PremiumToBaseRatio = curTicker.PremiumToBaseRatio,
                                    InvertRate         = curTicker.InvertRate
                                };
                            }
                            continue;
                        }

                        // строка содержит заголовок?
                        // EURO FX C (EU)
                        // BRIT PND-P EU
                        CMETickerInfo        tick;
                        CMEBulletinReference tickRef;
                        if (bulletinInfo.FindTicker(parts, out tick, out tickRef, SectionNum))
                        {
                            if (futuresInfo != null)
                            {
                                if (futuresInfo.Ticker == null)
                                {
                                    futuresInfo.Ticker = tick;
                                }
                            }
                            curTicker    = tick;
                            curTickerRef = tickRef;
                            continue;
                        }

                        var row = CMEBulletinTableRow.ParseLine(line);
                        if (row != null && curTable != null)
                        {
                            curTable.rows.Add(row);
                        }
                        if (row == null) // строка содержит данные по фьючам?
                        {
                            var summ = CheckFutureInfoLine(parts);
                            if (summ != null)
                            {
                                futuresInfo = summ;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.ErrorFormat("CMEDocumentParser.ParseTxtDocument parse line: \"{0}\", line:[{1}]",
                                           ex.Message, line);
                    }
                }
            }
            try
            {
                CMEBulletinTable.MergeSameTables(tables);
            }
            catch (Exception ex)
            {
                Logger.Error("CMEDocumentParser.ParseTxtDocument MergeSameTables", ex);
            }

            return(true);
        }
예제 #3
0
        public CMETickerInfoCollection(string xmlFile)
        {
            //<Ticker BaseActive="EURUSD" StrikeToBase="1000">
            //    <BulletinRef Type="CALL" Style="American" Title="EURO FX CALL" Section="39" />
            //    <BulletinRef Type="CALL" Style="European" Title="EURO FX C EU" Section="39" />
            //    <BulletinRef Type="PUT" Style="American" Title="EURO FX PUT" Section="39" />
            //    <BulletinRef Type="PUT" Style="European" Title="EURO FX P EU" Section="39" />
            //</Ticker>

            if (!File.Exists(xmlFile))
            {
                throw new FileNotFoundException(xmlFile);
            }
            var doc = new XmlDocument();

            doc.Load(xmlFile);
            if (doc.DocumentElement == null)
            {
                throw new Exception("Xml doc: document element is missing");
            }

            // номера бюллетеней и инструменты
            var nodes = doc.DocumentElement.SelectNodes("Ticker");

            if (nodes == null)
            {
                throw new Exception("No Ticker entry in XML root");
            }
            if (nodes.Count == 0)
            {
                throw new Exception("No Ticker entry in XML root");
            }


            foreach (XmlElement node in nodes)
            {
                var ticker = new CMETickerInfo(node.Attributes["BaseActive"].Value,
                                               node.Attributes["StrikeToBase"].Value.ToDecimalUniform(),
                                               Convert.ToBoolean(node.Attributes["Invert"].Value));
                ticker.PremiumToBaseRatio = node.Attributes["PremiumToBase"] != null
                                                ? node.Attributes["PremiumToBase"].Value.ToInt()
                                                : ticker.StrikeToBaseRatio;

                foreach (XmlElement nodeRef in node.ChildNodes)
                {
                    var bulRef = new CMEBulletinReference
                    {
                        OptionStyle = (OptionStyle)Enum.Parse(typeof(OptionStyle),
                                                              nodeRef.Attributes["Style"].Value),
                        OptionType = (OptionType)Enum.Parse(typeof(OptionType),
                                                            nodeRef.Attributes["Type"].Value),
                        Section = nodeRef.Attributes["Section"].Value,
                        Title   = nodeRef.Attributes["Title"].Value
                    };
                    ticker.bulletinReferences.Add(bulRef);
                    if (!sectionsToParse.Contains(bulRef.Section))
                    {
                        sectionsToParse.Add(bulRef.Section);
                    }
                }
                tickers.Add(ticker);
            }
        }
예제 #4
0
        public bool FindTicker(string[] lineParts, out CMETickerInfo ticker, 
            out CMEBulletinReference reference, string section)
        {
            ticker = null;
            reference = null;

            var title = string.Join(" ", lineParts);
            foreach (var tick in tickers)
            {
                foreach (var tickRef in tick.bulletinReferences)
                {
                    if (tickRef.Section == section && tickRef.Title == title)
                    {
                        ticker = tick;
                        reference = tickRef;
                        return true;
                    }
                }
            }
            return false;
        }
예제 #5
0
        public CMETickerInfoCollection(string xmlFile)
        {
            //<Ticker BaseActive="EURUSD" StrikeToBase="1000">
            //    <BulletinRef Type="CALL" Style="American" Title="EURO FX CALL" Section="39" />
            //    <BulletinRef Type="CALL" Style="European" Title="EURO FX C EU" Section="39" />
            //    <BulletinRef Type="PUT" Style="American" Title="EURO FX PUT" Section="39" />
            //    <BulletinRef Type="PUT" Style="European" Title="EURO FX P EU" Section="39" />
            //</Ticker>

            if (!File.Exists(xmlFile)) throw new FileNotFoundException(xmlFile);
            var doc = new XmlDocument();
            doc.Load(xmlFile);
            if (doc.DocumentElement == null)
                throw new Exception("Xml doc: document element is missing");

            // номера бюллетеней и инструменты
            var nodes = doc.DocumentElement.SelectNodes("Ticker");
            if (nodes == null) throw new Exception("No Ticker entry in XML root");
            if (nodes.Count == 0) throw new Exception("No Ticker entry in XML root");

            foreach (XmlElement node in nodes)
            {
                var ticker = new CMETickerInfo(node.Attributes["BaseActive"].Value,
                                               node.Attributes["StrikeToBase"].Value.ToDecimalUniform(),
                                               Convert.ToBoolean(node.Attributes["Invert"].Value));
                ticker.PremiumToBaseRatio = node.Attributes["PremiumToBase"] != null
                                                ? node.Attributes["PremiumToBase"].Value.ToInt()
                                                : ticker.StrikeToBaseRatio;

                foreach (XmlElement nodeRef in node.ChildNodes)
                {
                    var bulRef = new CMEBulletinReference
                                     {
                                         OptionStyle = (OptionStyle) Enum.Parse(typeof (OptionStyle),
                                                                                nodeRef.Attributes["Style"].Value),
                                         OptionType = (OptionType) Enum.Parse(typeof (OptionType),
                                                                              nodeRef.Attributes["Type"].Value),
                                         Section = nodeRef.Attributes["Section"].Value,
                                         Title = nodeRef.Attributes["Title"].Value
                                     };
                    ticker.bulletinReferences.Add(bulRef);
                    if (!sectionsToParse.Contains(bulRef.Section))
                        sectionsToParse.Add(bulRef.Section);
                }
                tickers.Add(ticker);
            }
        }