Example #1
0
        public static Dictionary <int, MtReportDeal> ParseMtReport(string inputFile)
        {
            Dictionary <int, MtReportDeal> ret = new Dictionary <int, MtReportDeal>();
            DateTime currentDate     = new DateTime(2009, 1, 1);
            string   startDealString = "<th colspan=\"13\" style=\"height: 25px\"><div style=\"font: 10pt Tahoma\"><b>Deals</b></div></th>";
            bool     startDeal       = false;

            System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(
                "^<tr bgcolor=\"(#F7F7F7|#FFFFFF)\" align=right>(.*?)</tr>$",
                System.Text.RegularExpressions.RegexOptions.Compiled);
            // <td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td>
            System.Text.RegularExpressions.Match match = null;
            using (StreamReader sr = new StreamReader(inputFile))
            {
                while (true)
                {
                    if (sr.EndOfStream)
                    {
                        break;
                    }
                    if (currentDate > System.DateTime.Now)
                    {
                        break;
                    }

                    string s = sr.ReadLine();
                    if (string.IsNullOrEmpty(s))
                    {
                        continue;
                    }
                    if (!startDeal)
                    {
                        startDeal = s.Contains(startDealString);
                        if (!startDeal)
                        {
                            continue;
                        }
                    }
                    //if (match == null || !match.Success)
                    match = r.Match(s.Trim());
                    if (match.Success)
                    {
                        try
                        {
                            MtReportDeal i = new MtReportDeal();

                            string   con = match.Groups[2].Value;
                            string[] ss  = con.Split(new string[] { "<td>", "</td>" }, StringSplitOptions.RemoveEmptyEntries);
                            if (ss.Length != 13)
                            {
                                continue;
                            }

                            i.Time   = Convert.ToDateTime(ss[0]);
                            i.Deal   = Convert.ToInt32(ss[1].Replace(" ", ""));
                            i.Symbol = ss[2].Replace(" ", "");
                            i.Type   = ss[3].Replace(" ", "");
                            if (i.Type == "balance")
                            {
                                continue;
                            }
                            i.Direction  = ss[4].Replace(" ", "");
                            i.Volume     = Convert.ToDouble(ss[5].Replace(" ", ""));
                            i.Price      = Convert.ToDouble(ss[6].Replace(" ", ""));
                            i.Order      = Convert.ToInt32(ss[7].Replace(" ", ""));
                            i.Commission = Convert.ToDouble(ss[8].Replace(" ", ""));
                            i.Swap       = Convert.ToDouble(ss[9].Replace(" ", ""));
                            i.Profit     = Convert.ToDouble(ss[10].Replace(" ", ""));
                            i.Balance    = Convert.ToDouble(ss[11].Replace(" ", ""));
                            i.Comment    = ss[12].Replace(" ", "");

                            ret[i.Deal] = i;

                            string[] ss2 = i.Comment.Split(':');
                            if (ss2.Length == 3)
                            {
                                i.CorrespondDeal = Convert.ToInt32(ss2[2]);
                                ret[i.CorrespondDeal].CorrespondDeal = i.Deal;
                            }
                            else if (ss2.Length == 2)
                            {
                            }
                            else
                            {
                                throw new AssertException("ss2's Length is invalid.");
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            return(ret);
        }
Example #2
0
        public static Dictionary<int, MtReportDeal> ParseMtReport(string inputFile)
        {
            Dictionary<int, MtReportDeal> ret = new Dictionary<int, MtReportDeal>();
            DateTime currentDate = new DateTime(2009, 1, 1);
            string startDealString = "<th colspan=\"13\" style=\"height: 25px\"><div style=\"font: 10pt Tahoma\"><b>Deals</b></div></th>";
            bool startDeal = false;
            System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(
                "^<tr bgcolor=\"(#F7F7F7|#FFFFFF)\" align=right>(.*?)</tr>$",
                System.Text.RegularExpressions.RegexOptions.Compiled);
            // <td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td>
            System.Text.RegularExpressions.Match match = null;
            using (StreamReader sr = new StreamReader(inputFile))
            {
                while (true)
                {
                    if (sr.EndOfStream)
                        break;
                    if (currentDate > System.DateTime.Now)
                        break;

                    string s = sr.ReadLine();
                    if (string.IsNullOrEmpty(s))
                        continue;
                    if (!startDeal)
                    {
                        startDeal = s.Contains(startDealString);
                        if (!startDeal)
                            continue;
                    }
                    //if (match == null || !match.Success)
                    match = r.Match(s.Trim());
                    if (match.Success)
                    {
                        try
                        {
                            MtReportDeal i = new MtReportDeal();

                            string con = match.Groups[2].Value;
                            string[] ss = con.Split(new string[] { "<td>", "</td>" }, StringSplitOptions.RemoveEmptyEntries);
                            if (ss.Length != 13)
                                continue;

                            i.Time = Convert.ToDateTime(ss[0]);
                            i.Deal = Convert.ToInt32(ss[1].Replace(" ", ""));
                            i.Symbol = ss[2].Replace(" ", "");
                            i.Type = ss[3].Replace(" ", "");
                            if (i.Type == "balance")
                                continue;
                            i.Direction = ss[4].Replace(" ", "");
                            i.Volume = Convert.ToDouble(ss[5].Replace(" ", ""));
                            i.Price = Convert.ToDouble(ss[6].Replace(" ", ""));
                            i.Order = Convert.ToInt32(ss[7].Replace(" ", ""));
                            i.Commission = Convert.ToDouble(ss[8].Replace(" ", ""));
                            i.Swap = Convert.ToDouble(ss[9].Replace(" ", ""));
                            i.Profit = Convert.ToDouble(ss[10].Replace(" ", ""));
                            i.Balance = Convert.ToDouble(ss[11].Replace(" ", ""));
                            i.Comment = ss[12].Replace(" ", "");

                            ret[i.Deal] = i;

                            string[] ss2 = i.Comment.Split(':');
                            if (ss2.Length == 3)
                            {
                                i.CorrespondDeal = Convert.ToInt32(ss2[2]);
                                ret[i.CorrespondDeal].CorrespondDeal = i.Deal;
                            }
                            else if (ss2.Length == 2)
                            {
                            }
                            else
                                throw new AssertException("ss2's Length is invalid.");
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            return ret;
        }