Exemple #1
0
        private MapFileResolver GetMapFileResolver(string market)
        {
            if (market != QuantConnect.Market.USA.ToLowerInvariant())
            {
                // don't explode for other markets which request map files and we don't have
                return(MapFileResolver.Empty);
            }
            var timestamp        = DateTime.UtcNow.ConvertFromUtc(TimeZones.NewYork);
            var todayNewYork     = timestamp.Date;
            var yesterdayNewYork = todayNewYork.AddDays(-1);

            // start the search with yesterday, today's file will be available tomorrow
            var count = 0;
            var date  = yesterdayNewYork;

            do
            {
                var zipFileName = Path.Combine(Globals.DataFolder, MapFileZipHelper.GetMapFileZipFileName(market, date));

                // Fetch a stream for our zip from our data provider
                var stream = _dataProvider.Fetch(zipFileName);

                // If we found a file we can read it
                if (stream != null)
                {
                    Log.Trace("LocalZipMapFileProvider.Get({0}): Fetched map files for: {1} NY", market, date.ToShortDateString());
                    var result = new MapFileResolver(MapFileZipHelper.ReadMapFileZip(stream));
                    stream.DisposeSafely();
                    return(result);
                }

                // prevent infinite recursion if something is wrong
                if (count++ > 30)
                {
                    throw new InvalidOperationException($"LocalZipMapFileProvider couldn't find any map files going all the way back to {date}");
                }

                date = date.AddDays(-1);
            }while (true);
        }
        private MapFileResolver GetMapFileResolver(AuxiliaryDataKey auxiliaryDataKey)
        {
            var market           = auxiliaryDataKey.Market;
            var timestamp        = DateTime.UtcNow.ConvertFromUtc(TimeZones.NewYork);
            var todayNewYork     = timestamp.Date;
            var yesterdayNewYork = todayNewYork.AddDays(-1);

            // start the search with yesterday, today's file will be available tomorrow
            var count = 0;
            var date  = yesterdayNewYork;

            do
            {
                var zipFileName = MapFileZipHelper.GetMapFileZipFileName(market, date, auxiliaryDataKey.SecurityType);

                // Fetch a stream for our zip from our data provider
                var stream = _dataProvider.Fetch(zipFileName);

                // If we found a file we can read it
                if (stream != null)
                {
                    Log.Trace("LocalZipMapFileProvider.Get({0}): Fetched map files for: {1} NY", market, date.ToShortDateString());
                    var result = new MapFileResolver(MapFileZipHelper.ReadMapFileZip(stream, market, auxiliaryDataKey.SecurityType));
                    stream.DisposeSafely();
                    return(result);
                }

                // prevent infinite recursion if something is wrong
                if (count++ > 30)
                {
                    throw new InvalidOperationException($"LocalZipMapFileProvider couldn't find any map files going all the way back to {date}");
                }

                date = date.AddDays(-1);
            }while (true);
        }