Example #1
0
        public List <CtpInfo> LoadCtpInfo(string fileName)
        {
            //MessageBox.Show(fileName);
            using (Stream resourceStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (StreamReader reader = new StreamReader(resourceStream, Encoding.GetEncoding("GB2312")))
                {
                    var strings = reader.ReadToEnd().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

                    //textBox1.Text = strings.Length.ToString();

                    var res = new List <CtpInfo>(strings.Length);


                    for (int i = 0; i < strings.Length; i++)
                    {
                        //string line = strings[i];
                        string[] subLines = strings[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        CtpInfo  data     = new CtpInfo();
                        //对每一行文本按<>结构进行数据转换
                        CtpTxt2Charts(subLines, out data);
                        DateTime date   = data.date;
                        Double   open   = data.open;
                        Double   high   = data.high;
                        Double   low    = data.low;
                        Double   close  = data.close;
                        Double   volume = data.volume;
                        Double   hold   = data.hold;

                        res.Add(
                            new CtpInfo
                        {
                            date   = date,
                            open   = open,
                            high   = high,
                            low    = low,
                            close  = close,
                            volume = volume
                        });
                    }
                    return(res);
                }
            }
        }
Example #2
0
        //private NPlot.Windows.PlotSurface2D myplot;



        // ----------------------------------- Helper
        void CtpTxt2Charts(string[] vitems, out CtpInfo data)
        {
            //vitems[0]=20160101;
            data        = new CtpInfo();
            data.open   = Double.Parse(vitems[2].Trim());
            data.high   = Double.Parse(vitems[3].Trim());
            data.low    = Double.Parse(vitems[4].Trim());
            data.close  = Double.Parse(vitems[5].Trim());
            data.volume = Double.Parse(vitems[6].Trim());
            data.hold   = Double.Parse(vitems[7].Trim());
            int year  = Int32.Parse(vitems[0].Trim().Substring(0, 4));
            int month = Int32.Parse(vitems[0].Trim().Substring(4, 2));
            int day   = Int32.Parse(vitems[0].Trim().Substring(6, 2));
            //vitems[1]=0.121212;

            int      time  = (int)(Double.Parse(vitems[1].Trim()) * 1000000);
            int      h     = time / 10000;
            int      m     = Int32.Parse(vitems[1].Trim().Substring(4, 2));
            int      s     = Int32.Parse(vitems[1].Trim().Substring(6, 2));
            DateTime date1 = new DateTime(year, month, day, h, m, s);

            data.date = date1;
        }