Ejemplo n.º 1
0
        public PriceSet GetPrices(TradingSymbol symbol, int year, int month)
        {
            int    price_set_index     = GetPriceSetIndex(year, month);
            string price_set_file_path = GetPriceSetFilePath(symbol, year, month);

            if (!data_loaded.ContainsKey(symbol))
            {
                data_loaded[symbol] = new Dictionary <int, PriceSet>();
            }

            if (data_loaded[symbol].ContainsKey(price_set_index))
            {
                return(data_loaded[symbol][price_set_index]);
            }
            else
            {
                if (File.Exists(price_set_file_path))
                {
                    data_loaded[symbol][price_set_index] = PriceSet.Read(new BinaryReader(File.Open(price_set_file_path, FileMode.Open)));
                }
                else
                {
                    data_loaded[symbol][price_set_index] = new PriceSet(symbol, new DateTimeUTC(year, month, 1), new DateTimeUTC(year, month + 1, 1));
                }


                return(data_loaded[symbol][price_set_index]);
            }
        }
Ejemplo n.º 2
0
        public static PriceSet GetPriceSet(TradingSymbol trading_symbol)
        {
            string data_path = Path.Combine(binary_data_root_path, trading_symbol.Broker, trading_symbol.Account, trading_symbol.Symbol);

            if (!Directory.Exists(data_path))
            {
                throw new Exception("No data for trading symbol: " + trading_symbol);
            }
            string[] files = Directory.GetFiles(data_path);
            if (files.Length != 1)
            {
                throw new Exception("No unique data for trading symbol: " + trading_symbol);
            }

            using (BinaryReader reader = new BinaryReader(new FileStream(files[0], FileMode.Open)))
            {
                return(PriceSet.Read(reader));
            }
        }