Exemple #1
0
        public Master FindBySymbol(string Symbol, out XMaster xm)
        {
            xm = null;
            if (Masters != null)
            {
                foreach (Master m in Masters)
                {
                    if (m.symbol == Symbol)
                    {
                        return(m);
                    }
                }
            }

            if (XMasters != null)
            {
                foreach (XMaster m in XMasters)
                {
                    if (m.StockSymbol == Symbol)
                    {
                        xm = m;
                        return(null);
                    }
                }
            }
            return(null);
        }
Exemple #2
0
        private void LoadXMaster()
        {
            using (FileStream fs = ReadData(FilePath + "XMASTER"))
            {
                XMasters = new XMaster[fs.Length / 150 - 1];
                using (BinaryReader br = new BinaryReader(fs))
                {
                    br.ReadBytes(150);
                    int i = 0;
                    do
                    {
                        XMasters[i]          = new XMaster();
                        XMasters[i].Unknown1 = br.ReadByte();

                        XMasters[i].StockSymbol = TrimToZero(Encoding.ASCII.GetString(br.ReadBytes(15)));
                        XMasters[i].StockName   = TrimToZero(Encoding.ASCII.GetString(br.ReadBytes(46)));
                        XMasters[i].Unknown2    = br.ReadBytes(3);
                        XMasters[i].Fn          = br.ReadInt16();
                        XMasters[i].Unknown3    = br.ReadBytes(13);
                        XMasters[i].EndDate     = br.ReadInt32();
                        XMasters[i].Unknown4    = br.ReadBytes(20);
                        XMasters[i].StartDate   = br.ReadInt32();
                        XMasters[i].StartDate2  = br.ReadInt32();
                        XMasters[i].Unknown5    = br.ReadBytes(4);
                        XMasters[i].EndDate2    = br.ReadInt32();
                        XMasters[i].Unknown6    = br.ReadBytes(30);
                        i++;
                    } while (i < XMasters.Length);
                }
            }
        }
Exemple #3
0
        public override void SaveData(string Symbol, IDataProvider idp, Stream OutStream, DateTime Start, DateTime End, bool Intraday)
        {
            CommonDataProvider cdp = (CommonDataProvider)idp;

            if (Symbol != null && Symbol != "")
            {
                int     Count = cdp.Count;
                XMaster xm;
                Master  m         = FindBySymbol(Symbol, out xm);
                bool    NeedSave  = false;
                bool    NeedSaveX = false;

                Fields = (byte)(7 + (Intraday?1:0));
                if (m == null && xm == null)
                {
                    int NowNumber = MaxNum + 1;
                    if (NowNumber > 255)
                    {
                        xm    = new XMaster();
                        xm.Fn = (short)NowNumber;
                        ArrayList al = new ArrayList(XMasters);
                        xm.StockSymbol = Symbol;
                        xm.StockName   = cdp.GetStringData("Name");
                        if (xm.StockName == null)
                        {
                            xm.StockName = Symbol;
                        }
                        al.Add(xm);
                        XMasters  = (XMaster[])al.ToArray(typeof(XMaster));
                        NeedSaveX = true;
                    }
                    else
                    {
                        m          = new Master();
                        m.file_num = (byte)NowNumber;
                        ArrayList al = new ArrayList(Masters);
                        m.symbol     = Symbol;
                        m.num_fields = (byte)Fields;
                        m.issue_name = cdp.GetStringData("Name");
                        if (m.issue_name == null)
                        {
                            m.issue_name = Symbol;
                        }
                        al.Add(m);
                        Masters  = (Master[])al.ToArray(typeof(Master));
                        NeedSave = true;
                    }
                }

                double[] Date    = (double[])cdp["DATE"];
                double[] Open    = (double[])cdp["OPEN"];
                double[] High    = (double[])cdp["HIGH"];
                double[] Low     = (double[])cdp["LOW"];
                double[] Close   = (double[])cdp["CLOSE"];
                double[] Volume  = (double[])cdp["VOLUME"];
                double[] OpenInt = (double[])cdp["ADJCLOSE"];
                float[]  ff      = new float[Count * Fields];

                for (int i = 0; i < Count; i++)
                {
                    int      j = 0;
                    DateTime D = DateTime.FromOADate(Date[i]);
                    ff[i * Fields + j] = (D.Year - 1900) * 10000 + D.Month * 100 + D.Day;
                    if (Fields == 8)
                    {
                        j = 1;
                        ff[i * Fields + j] = D.Hour * 10000 + D.Minute * 100 + D.Second;
                    }
                    ff[i * Fields + 1 + j] = (float)Open[i];
                    ff[i * Fields + 2 + j] = (float)High[i];
                    ff[i * Fields + 3 + j] = (float)Low[i];
                    ff[i * Fields + 4 + j] = (float)Close[i];
                    ff[i * Fields + 5 + j] = (float)Volume[i];
                    ff[i * Fields + 6 + j] = (float)Close[i];
                }
                fieee2msbin(ff);
                byte[] bs = new byte[ff.Length * 4];
                Buffer.BlockCopy(ff, 0, bs, 0, bs.Length);

                string s = LookupDataFile(Symbol, cdp);               //FilePath+"F"+m.file_num+".DAT";
                using (FileStream fs = File.Create(s))
                    fs.Write(bs, 0, bs.Length);
                if (NeedSave)
                {
                    SaveMaster();
                }
                if (NeedSaveX)
                {
                    SaveXMaster();
                }
            }
        }