Example #1
0
        public MetaStockTable FilterPeriod(DateTime Start, DateTime End)
        {
            MetaStockTable M = new MetaStockTable();

            for (int t = 0; t < this.Count; t++)
            {
                if (this[t].Day >= Start && this[t].Day <= End)
                {
                    M.Add(this[t]);
                }
            }
            return(M);
        }
Example #2
0
        public MetaStockTable ReadSymbol(string simbolo)
        {
            if (StockCache.ContainsKey(simbolo))
            {
                return(StockCache[simbolo]);
            }

            // trova il simbolo
            foreach (CatalogEntry CE in MainDir)
            {
                if (CE.symbol.Trim() == simbolo)
                {
                    MetaStockTable tab = new MetaStockTable();
                    tab.Symbol = CE.symbol;

                    FileStream   F  = new FileStream(CE.filename, FileMode.Open, FileAccess.Read);
                    BinaryReader BR = new BinaryReader(F);

                    UInt16 max_recs = BR.ReadUInt16();  // 0 ==> unlimited size
                    UInt16 last_rec = BR.ReadUInt16();  // dathdr7 = 1; ctdata7 starts with 2

                    if (CE.numfields == 5)
                    {
                        BR.ReadBytes(16);                    // zeroes
                    }
                    else if (CE.numfields == 6)
                    {
                        BR.ReadBytes(20);                         // zeroes
                    }
                    else if (CE.numfields == 7)
                    {
                        BR.ReadBytes(24);                         // zeroes
                    }
                    // mega toppa, talvolta il file inizia con 20 zeri invece di 24!
                    // if(bbb[23]!=0) F.Seek(-4, SeekOrigin.Current);

                    for (int t = 1; t < last_rec; t++)
                    {
                        MetaStockRow data = new MetaStockRow();
                        data.Day   = DateFromSingle(ConvertMbf4ToFloat(BR.ReadBytes(4)));
                        data.Open  = ConvertMbf4ToFloat(BR.ReadBytes(4));
                        data.High  = ConvertMbf4ToFloat(BR.ReadBytes(4));
                        data.Low   = ConvertMbf4ToFloat(BR.ReadBytes(4));
                        data.Close = ConvertMbf4ToFloat(BR.ReadBytes(4));
                        if (CE.numfields > 5)
                        {
                            data.Volume = ConvertMbf4ToFloat(BR.ReadBytes(4));
                        }
                        if (CE.numfields > 6)
                        {
                            data.OpenInterest = ConvertMbf4ToFloat(BR.ReadBytes(4));
                        }
                        tab.Add(data);
                    }

                    BR.Close();
                    F.Close();

                    StockCache.Add(simbolo, tab);

                    return(tab);
                }
            }
            throw new Exception("Symbol " + simbolo + " not found");
        }