示例#1
0
 public WriterDataItem(FileStream stream, PbTickSerializer serializer, string path,string symbol)
 {
     Stream = stream;
     Serializer = serializer;
     _Symbol = symbol;
     _Path = path;
     LastWriteTime = DateTime.Now;
 }
示例#2
0
 public WriterDataItem(FileStream stream, PbTickSerializer serializer, string path, string symbol)
 {
     Stream        = stream;
     Serializer    = serializer;
     _Symbol       = symbol;
     _Path         = path;
     LastWriteTime = DateTime.Now;
 }
示例#3
0
        public void AddInstrument(string symbol, double tickSize, double factor, int Time_ssf_Diff)
        {
            lock (locker)
            {
                WriterDataItem item;
                if (!Items.TryGetValue(symbol, out item))
                {
                    var serializer = new PbTickSerializer();
                    if (tickSize > 0)
                    {
                        serializer.Codec.Config.SetTickSize(tickSize);
                        serializer.Codec.TickSize = serializer.Codec.Config.GetTickSize();
                    }
                    if (factor > 0)
                    {
                        serializer.Codec.Config.ContractMultiplier = factor;
                    }
                    serializer.Codec.Config.Time_ssf_Diff = Time_ssf_Diff;

                    Items.Add(symbol, new WriterDataItem(null, serializer, _path, symbol));
                }
                else
                {
                    // 有可能要不关软件,连续工作,但tickSize又发生了变化
                    var serializer = item.Serializer;
                    if (serializer != null)
                    {
                        if (tickSize > 0)
                        {
                            serializer.Codec.Config.SetTickSize(tickSize);
                            serializer.Codec.TickSize = serializer.Codec.Config.GetTickSize();
                        }
                        if (factor > 0)
                        {
                            serializer.Codec.Config.ContractMultiplier = factor;
                        }
                        serializer.Codec.Config.Time_ssf_Diff = Time_ssf_Diff;
                    }
                }
            }
        }
示例#4
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 pts = new PbTickSerializer();
                pts.Write(this.listTickData, pathChosen);

                ValueChanged(false);
            }
        }
示例#5
0
        public void AddInstrument(string symbol, double tickSize, double factor, int Time_ssf_Diff)
        {
            lock (locker)
            {
                WriterDataItem item;
                if (!Items.TryGetValue(symbol, out item))
                {
                    var serializer = new PbTickSerializer();
                    if (tickSize > 0)
                    {
                        serializer.Codec.Config.SetTickSize(tickSize);
                        serializer.Codec.TickSize = serializer.Codec.Config.GetTickSize();
                    }
                    if (factor > 0)
                        serializer.Codec.Config.ContractMultiplier = factor;
                    serializer.Codec.Config.Time_ssf_Diff = Time_ssf_Diff;

                    Items.Add(symbol, new WriterDataItem(null, serializer, _path, symbol));
                }
                else
                {
                    // 有可能要不关软件,连续工作,但tickSize又发生了变化
                    var serializer = item.Serializer;
                    if (serializer != null)
                    {
                        if (tickSize > 0)
                        {
                            serializer.Codec.Config.SetTickSize(tickSize);
                            serializer.Codec.TickSize = serializer.Codec.Config.GetTickSize();
                        }
                        if (factor > 0)
                            serializer.Codec.Config.ContractMultiplier = factor;
                        serializer.Codec.Config.Time_ssf_Diff = Time_ssf_Diff;
                    }
                }
            }
        }
示例#6
0
        static void Main3(string[] args)
        {
            FileInfo fi = new FileInfo(@"F:\办公文档\数据\DepthDataShow\20150120.txt");
            //FileInfo fo = new FileInfo(@"F:\BaiduYunDownload\DepthDataShow\20150120.pd0");

            PbTickSerializer pts = new PbTickSerializer();

            CCC ccc = new CCC();
            CCC last_ccc = new CCC();

            AAA last = new AAA();
            last.buy = false;

            string last_symbol = "XXX";

            List<AAA> list = new List<AAA>();

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

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

                        AAA a = new AAA();
                        a.symbol = arr[1];
                        a.buy = arr[2] == "0";
                        a.price = double.Parse(arr[3]);
                        a.size = int.Parse(arr[4]);


                        if (last.buy == false && a.buy == true)
                        {
                            // 快照的切换点,把上次的存储都取出来,进行保存
                            // sell里先存的数字大的,后存的数字小的,最后的是卖一
                            // buy里也是先存数字大的,后存数字小的,最前的买一
                            // 
                            foreach (var kv in ccc.dict)
                            {
                                kv.Value.MakeTick();

                                ccc.GetSerializer(kv.Key).Write(kv.Value.tick,
                                    ccc.GetStream(kv.Key));
                            }

                            ccc.dict.Clear();
                        }

                        BBB bbb = ccc.Get(a.symbol);
                        bbb.symbol = a.symbol;
                        bbb.time = arr[0];

                        if (bbb.symbol == "cu1502")
                        {
                            int nTest = 1;
                        }

                        if (a.buy)
                        {
                            bbb.AddBid(a);
                        }
                        else
                        {
                            bbb.AddAsk(a);
                        }


                        last = a;
                        last_symbol = a.symbol;

                        //if (i < 4000)
                        //    Console.WriteLine(str);
                        //if (i > 1000)
                        //    break;
                    } while (str != null);
                    file.Close();
                }
            }
        }
示例#7
0
 public PbTickSerializer GetSerializer(string symbol)
 {
     PbTickSerializer list;
     if (!dict2.TryGetValue(symbol, out list))
     {
         list = new PbTickSerializer();
         dict2.Add(symbol, list);
     }
     return list;
 }
示例#8
0
        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();
                }
            }
        }