示例#1
0
        public static bool WriteQuotationDataToFile(String Symbol, QuotationData Data, bool Rewriting)
        {
            bool bRet = false;

            String FilePath = sQuotationDataPath + Symbol;

            if (Directory.Exists(FilePath) == false)//如果不存在就创建file文件夹
            {
                Directory.CreateDirectory(FilePath);
            }

            FileStream file     = null;
            String     FileName = FilePath + "/" + DateTime.Now.ToString("yyyy-MM-dd");

            if (File.Exists(FileName) == false)
            {
                file = File.Create(FileName);
            }
            else
            {
                file = new FileStream(FileName, FileMode.Open);
            }

            if (file.CanWrite)
            {
                if (Rewriting)
                {
                    file.SetLength(0);
                }
                else
                {
                    file.Seek(0, SeekOrigin.End);
                }
                StreamWriter writer = new StreamWriter(file);

                String str = Data.TradingTime + "|";
                str += Data.Base.LastClose + "|";
                str += Data.Base.OpenPrice + "|";
                str += Data.Statistics.CurBidAmount + "|";
                str += Data.Statistics.AverBidPrice + "|";
                str += Data.Statistics.CurAskAmount + "|";
                str += Data.Statistics.AverAskPrice + "|";
                str += Data.Statistics.CancelBidNum + "|";
                str += Data.Statistics.CancelBidAmount + "|";
                str += Data.Statistics.CancelAskNum + "|";
                str += Data.Statistics.CancelAskAmount + "|";
                str += Data.Statistics.TotalBidNum + "|";
                str += Data.Statistics.TotalAskNum;

                writer.WriteLine(str);

                writer.Flush();
            }

            file.Close();

            return(bRet);
        }
示例#2
0
        public void Copy(QuotationData Other)
        {
            Name        = Other.Name;
            TradingTime = Other.TradingTime;

            Base.Copy(Other.Base);
            Statistics.Copy(Other.Statistics);
            CrossQuotes.Copy(Other.CrossQuotes);
        }
示例#3
0
        public static void ReadQuotationDataFromFile(String Symbol, DateTime Day, List <QuotationData> Data)
        {
            String FileName = sQuotationDataPath + Symbol + "/" + Day.ToString("yyyy-MM-dd");

            if (File.Exists(FileName) == false)
            {
                MessageBox.Show("路径错误!!!");
                return;
            }

            FileStream file = new FileStream(FileName, FileMode.Open);

            if (file.CanRead)
            {
                StreamReader reader = new StreamReader(file);
                String       str;

                while ((str = reader.ReadLine()) != null)
                {
                    string[] separator  = new string[] { "|" };
                    var      strElement = str.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                    if (strElement.Count() == 13)
                    {
                        QuotationData ele = new QuotationData();
                        ele.TradingTime                = strElement[0];
                        ele.Base.LastClose             = (float)Convert.ToDouble(strElement[1]);
                        ele.Base.OpenPrice             = (float)Convert.ToDouble(strElement[2]);
                        ele.Statistics.CurBidAmount    = (float)Convert.ToDouble(strElement[3]);
                        ele.Statistics.AverBidPrice    = (float)Convert.ToDouble(strElement[4]);
                        ele.Statistics.CurAskAmount    = (float)Convert.ToDouble(strElement[5]);
                        ele.Statistics.AverAskPrice    = (float)Convert.ToDouble(strElement[6]);
                        ele.Statistics.CancelBidNum    = Convert.ToInt32(strElement[7]);
                        ele.Statistics.CancelBidAmount = (float)Convert.ToDouble(strElement[8]);
                        ele.Statistics.CancelAskNum    = Convert.ToInt32(strElement[9]);
                        ele.Statistics.CancelAskAmount = (float)Convert.ToDouble(strElement[10]);
                        ele.Statistics.TotalBidNum     = Convert.ToInt32(strElement[11]);
                        ele.Statistics.TotalAskNum     = Convert.ToInt32(strElement[12]);

                        Data.Add(ele);
                    }
                }
            }

            file.Close();
        }