Exemple #1
0
        private void SaveChanges()
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "Portable Data Zero files (*.pd0)|*.pd0|All files (*.*)|*.*";
            DialogResult result = saveFileDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                string pathChosen = saveFileDialog.FileName;

                ViewToDataByViewType();

                PbTickSerializer.Write(this.listTickData, pathChosen);
                ValueChanged(false);
            }
        }
Exemple #2
0
        public static void _Main(string[] args)
        {
            string     symbol     = "AAPL";
            Framework  framework  = Framework.Current;
            Instrument instrument = framework.InstrumentManager.Get(symbol);
            DataSeries ds         = framework.DataManager.GetDataSeries(instrument, DataObjectType.Trade);

            PbTickSerializer pts = new PbTickSerializer();

            // 最关键的部分,需要提前设置
            pts.Codec.Config.SetTickSize(0.01);

            PbTick last = new PbTick();

            using (Stream stream = File.OpenWrite(@"D:\1.data"))
            {
                for (int i = 0; i < ds.Count; ++i)
                {
                    var    d    = ds[i];
                    Trade  t    = d as Trade;
                    PbTick tick = new PbTick();

                    // 必须设置数据中的TickSize
                    tick.Config = pts.Codec.Config;

                    pts.Codec.SetLastPrice(tick, t.Price);
                    pts.Codec.SetVolume(tick, t.Size);
                    pts.Codec.SetSymbol(tick, symbol);

                    // 时间设置也很关键
                    pts.Codec.SetActionDay(tick, t.DateTime.Date);
                    pts.Codec.SetUpdateTime(tick, t.DateTime - t.DateTime.Date);

                    // 写入流
                    pts.Write(tick, new Stream[] { stream });
                }
                stream.Close();
            }
        }
Exemple #3
0
        public void TestReadCsvLeve2()
        {
            FileInfo fi = new FileInfo(@"F:\BaiduYunDownload\20141225\20141225.csv");
            FileInfo fo = new FileInfo(@"F:\BaiduYunDownload\20141225\20141225.pd0");

            PbTickSerializer pts = new PbTickSerializer();


            using (Stream stream = File.Open(@"F:\BaiduYunDownload\20141225\20141225.pd0", FileMode.Create))
            {
                using (StreamReader file = new StreamReader(fi.OpenRead()))
                {
                    int    i   = 0;
                    string str = file.ReadLine();
                    do
                    {
                        ++i;
                        str = file.ReadLine();
                        if (str == null)
                        {
                            break;
                        }

                        string[] arr = str.Split(',');

                        PbTick tick = new PbTick();

                        pts.Codec.SetSymbol(tick, arr[0]);

                        tick.Config = new ConfigInfo().Default();

                        if (arr[0].StartsWith("TF"))
                        {
                            tick.Config.SetTickSize(0.002);
                            tick.Config.ContractMultiplier = 10000;
                        }
                        else
                        {
                            tick.Config.SetTickSize(0.2);
                            tick.Config.ContractMultiplier = 300;
                        }
                        tick.Config.Time_ssf_Diff = 5;

                        pts.Codec.Config = tick.Config;
                        pts.Codec.UseFlat(false);

                        //if(i == 1)
                        //{
                        //    tick.Split = new StockSplitInfo();
                        //    tick.Split.StockDividend = 10;
                        //}
                        //if(i == 2)
                        //{
                        //    tick.Split = new StockSplitInfo();
                        //    tick.Split.CashDividend = 10;
                        //}

                        tick.ActionDay = int.Parse(arr[5]);
                        int time = int.Parse(arr[6]);

                        tick.Time_HHmm      = time / 100000;
                        tick.Time_____ssf__ = time % 100000 / 100;
                        tick.Time________ff = time % 100;

                        pts.Codec.SetLastPrice(tick, double.Parse(arr[8]));
                        pts.Codec.SetHigh(tick, double.Parse(arr[9]));
                        pts.Codec.SetLow(tick, double.Parse(arr[10]));
                        pts.Codec.SetVolume(tick, int.Parse(arr[11]));
                        pts.Codec.SetTurnover(tick, int.Parse(arr[12]));

                        pts.Codec.SetOpenInterest(tick, int.Parse(arr[16]));

                        pts.Codec.SetAskPrice(tick, 1, double.Parse(arr[17]));
                        pts.Codec.SetAskPrice(tick, 2, double.Parse(arr[18]));
                        pts.Codec.SetAskPrice(tick, 3, double.Parse(arr[19]));
                        pts.Codec.SetAskPrice(tick, 4, double.Parse(arr[20]));
                        pts.Codec.SetAskPrice(tick, 5, double.Parse(arr[21]));

                        pts.Codec.SetAskSize(tick, 1, int.Parse(arr[22]));
                        pts.Codec.SetAskSize(tick, 2, int.Parse(arr[23]));
                        pts.Codec.SetAskSize(tick, 3, int.Parse(arr[24]));
                        pts.Codec.SetAskSize(tick, 4, int.Parse(arr[25]));
                        pts.Codec.SetAskSize(tick, 5, int.Parse(arr[26]));

                        pts.Codec.SetBidPrice(tick, 1, double.Parse(arr[27]));
                        pts.Codec.SetBidPrice(tick, 2, double.Parse(arr[28]));
                        pts.Codec.SetBidPrice(tick, 3, double.Parse(arr[29]));
                        pts.Codec.SetBidPrice(tick, 4, double.Parse(arr[30]));
                        pts.Codec.SetBidPrice(tick, 5, double.Parse(arr[31]));

                        pts.Codec.SetBidSize(tick, 1, int.Parse(arr[32]));
                        pts.Codec.SetBidSize(tick, 2, int.Parse(arr[33]));
                        pts.Codec.SetBidSize(tick, 3, int.Parse(arr[34]));
                        pts.Codec.SetBidSize(tick, 4, int.Parse(arr[35]));
                        pts.Codec.SetBidSize(tick, 5, int.Parse(arr[36]));

                        pts.Write(tick, new Stream[] { stream });
                    } while (str != null);
                    file.Close();
                }
            }
        }
Exemple #4
0
        public void TestReadCsvLeve1()
        {
            FileInfo fi = new FileInfo(@"F:\BaiduYunDownload\IF1406\IF1406.csv");
            FileInfo fo = new FileInfo(@"F:\BaiduYunDownload\IF1406\IF1406.pd0");

            PbTickSerializer pts = new PbTickSerializer();

            pts.Codec.Config.SetTickSize(0.2);
            pts.Codec.Config.Time_ssf_Diff = 5;

            using (Stream stream = File.Open(@"F:\BaiduYunDownload\IF1406\IF1406.pd0", FileMode.Create))
            {
                using (StreamReader file = new StreamReader(fi.OpenRead()))
                {
                    int    i   = 0;
                    string str = file.ReadLine();
                    do
                    {
                        ++i;
                        str = file.ReadLine();
                        if (str == null)
                        {
                            break;
                        }

                        string[] arr = str.Split(',');

                        DateTime dt      = DateTime.Parse(arr[0]).AddMilliseconds(int.Parse(arr[1]));
                        string   symbol  = arr[2];
                        double   price   = double.Parse(arr[3]);
                        int      vol     = int.Parse(arr[4]);
                        int      openint = int.Parse(arr[5]);
                        double   bid     = double.Parse(arr[6]);
                        int      bidSize = int.Parse(arr[7]);
                        double   ask     = double.Parse(arr[8]);
                        int      askSize = int.Parse(arr[9]);

                        PbTick tick = new PbTick();

                        tick.Config = pts.Codec.Config;

                        pts.Codec.SetLastPrice(tick, price);
                        pts.Codec.SetVolume(tick, vol);
                        pts.Codec.SetSymbol(tick, symbol);

                        pts.Codec.SetActionDay(tick, dt.Date);
                        pts.Codec.SetUpdateTime(tick, dt - dt.Date);

                        pts.Codec.SetBidPrice(tick, 1, bid);
                        pts.Codec.SetBidSize(tick, 1, bidSize);
                        pts.Codec.SetAskPrice(tick, 1, ask);
                        pts.Codec.SetAskSize(tick, 1, askSize);

                        pts.Write(tick, new Stream[] { stream });

                        //if (i == 1000000)
                        //    break;
                    } while (str != null);
                    file.Close();
                }
            }
            Console.WriteLine("结束了");
        }
        static void Main2(string[] args)
        {
            //读五档行情,然后存盘
            FileInfo fi = new FileInfo(@"d:\wukan\Desktop\20141225.csv");
            //FileInfo fo = new FileInfo(@"d:\wukan\Desktop\20141225.pd0");

            PbTickSerializer pts = new PbTickSerializer();


            using (Stream stream = File.Open(@"d:\wukan\Desktop\20141225_1.pd0", FileMode.Create))
            {
                using (StreamReader file = new StreamReader(fi.OpenRead()))
                {
                    int    i   = 0;
                    string str = file.ReadLine();
                    do
                    {
                        ++i;
                        str = file.ReadLine();
                        if (str == null)
                        {
                            break;
                        }

                        string[] arr = str.Split(',');

                        PbTick tick = new PbTick();

                        pts.Codec.SetSymbol(tick, arr[0]);

                        tick.Config = new ConfigInfo().Default();

                        if (arr[0].StartsWith("TF"))
                        {
                            tick.Config.SetTickSize(0.002);
                            tick.Config.ContractMultiplier = 10000;
                        }
                        else
                        {
                            tick.Config.SetTickSize(0.2);
                            tick.Config.ContractMultiplier = 300;
                        }
                        tick.Config.Time_ssf_Diff = 5;

                        pts.Codec.Config = tick.Config;


                        tick.ActionDay = int.Parse(arr[5]);
                        int time = int.Parse(arr[6]);

                        tick.Time_HHmm      = time / 100000;
                        tick.Time_____ssf__ = time % 100000 / 100;
                        tick.Time________ff = time % 100;

                        pts.Codec.SetLastPrice(tick, double.Parse(arr[8]));
                        pts.Codec.SetHigh(tick, double.Parse(arr[9]));
                        pts.Codec.SetLow(tick, double.Parse(arr[10]));
                        pts.Codec.SetVolume(tick, int.Parse(arr[11]));
                        pts.Codec.SetTurnover(tick, int.Parse(arr[12]));

                        pts.Codec.SetOpenInterest(tick, int.Parse(arr[16]));


                        tick.DepthList = new List <DepthItem>();

                        tick.DepthList.Add(new DepthItem(pts.Codec.PriceToTick(double.Parse(arr[31])), int.Parse(arr[36]), 0));
                        tick.DepthList.Add(new DepthItem(pts.Codec.PriceToTick(double.Parse(arr[30])), int.Parse(arr[35]), 0));
                        tick.DepthList.Add(new DepthItem(pts.Codec.PriceToTick(double.Parse(arr[29])), int.Parse(arr[34]), 0));
                        tick.DepthList.Add(new DepthItem(pts.Codec.PriceToTick(double.Parse(arr[28])), int.Parse(arr[33]), 0));
                        tick.DepthList.Add(new DepthItem(pts.Codec.PriceToTick(double.Parse(arr[27])), int.Parse(arr[32]), 0));

                        pts.Codec.SetAskPrice1(tick, double.Parse(arr[17]));

                        tick.DepthList.Add(new DepthItem(pts.Codec.PriceToTick(double.Parse(arr[17])), int.Parse(arr[22]), 0));
                        tick.DepthList.Add(new DepthItem(pts.Codec.PriceToTick(double.Parse(arr[18])), int.Parse(arr[23]), 0));
                        tick.DepthList.Add(new DepthItem(pts.Codec.PriceToTick(double.Parse(arr[19])), int.Parse(arr[24]), 0));
                        tick.DepthList.Add(new DepthItem(pts.Codec.PriceToTick(double.Parse(arr[20])), int.Parse(arr[25]), 0));
                        tick.DepthList.Add(new DepthItem(pts.Codec.PriceToTick(double.Parse(arr[21])), int.Parse(arr[26]), 0));


                        pts.Write(tick, stream);
                    } while (str != null);
                    file.Close();
                }
            }
        }