コード例 #1
0
        /// <summary>
        /// Creates a new <see cref="ISubscriptionDataSourceReader"/> capable of handling the specified <paramref name="source"/>
        /// </summary>
        /// <param name="source">The subscription data source to create a factory for</param>
        /// <param name="dataCacheProvider">Used to cache data</param>
        /// <param name="config">The configuration of the subscription</param>
        /// <param name="date">The date to be processed</param>
        /// <param name="isLiveMode">True for live mode, false otherwise</param>
        /// <returns>A new <see cref="ISubscriptionDataSourceReader"/> that can read the specified <paramref name="source"/></returns>
        public static ISubscriptionDataSourceReader ForSource(SubscriptionDataSource source, IDataCacheProvider dataCacheProvider, SubscriptionDataConfig config, DateTime date, bool isLiveMode)
        {
            ISubscriptionDataSourceReader    reader;
            TextSubscriptionDataSourceReader textReader = null;

            switch (source.Format)
            {
            case FileFormat.Csv:
                reader = textReader = new TextSubscriptionDataSourceReader(dataCacheProvider, config, date, isLiveMode);
                break;

            case FileFormat.Collection:
                reader = new CollectionSubscriptionDataSourceReader(dataCacheProvider, config, date, isLiveMode);
                break;

            case FileFormat.ZipEntryName:
                reader = new ZipEntryNameSubscriptionDataSourceReader(config, date, isLiveMode);
                break;

            case FileFormat.Index:
                return(new IndexSubscriptionDataSourceReader(dataCacheProvider, config, date, isLiveMode));

            default:
                throw new NotImplementedException("SubscriptionFactory.ForSource(" + source + ") has not been implemented yet.");
            }

            // wire up event handlers for logging missing files
            if (source.TransportMedium == SubscriptionTransportMedium.LocalFile)
            {
                var factory = config.GetBaseDataInstance();
                if (!factory.IsSparseData())
                {
                    reader.InvalidSource += (sender, args) => Log.Error($"SubscriptionDataSourceReader.InvalidSource(): File not found: {args.Source.Source}");
                    if (textReader != null)
                    {
                        textReader.CreateStreamReaderError += (sender, args) => Log.Error($"SubscriptionDataSourceReader.CreateStreamReaderError(): File not found: {args.Source.Source}");
                    }
                }
            }

            return(reader);
        }
コード例 #2
0
        public void ReadsZipEntryNames()
        {
            var time = new DateTime(2016, 03, 03, 12, 48, 15);
            var source = Path.Combine("TestData", "20151224_quote_american.zip");
            var config = new SubscriptionDataConfig(typeof (ZipEntryName), Symbol.Create("XLRE", SecurityType.Option, Market.USA), Resolution.Tick,
                TimeZones.NewYork, TimeZones.NewYork, false, false, false);
            var dataFileProvider = new DefaultDataFileProvider();
            var factory = new ZipEntryNameSubscriptionDataSourceReader(dataFileProvider, config, time, false);
            var expected = new[]
            {
                Symbol.CreateOption("XLRE", Market.USA, OptionStyle.American, OptionRight.Call, 21m, new DateTime(2016, 08, 19)),
                Symbol.CreateOption("XLRE", Market.USA, OptionStyle.American, OptionRight.Call, 22m, new DateTime(2016, 08, 19)),
                Symbol.CreateOption("XLRE", Market.USA, OptionStyle.American, OptionRight.Put, 37m, new DateTime(2016, 08, 19)),
            };

            var actual = factory.Read(new SubscriptionDataSource(source, SubscriptionTransportMedium.LocalFile, FileFormat.ZipEntryName)).ToList();

            // we only really care about the symbols
            CollectionAssert.AreEqual(expected, actual.Select(x => x.Symbol));
            Assert.IsTrue(actual.All(x => x is ZipEntryName));
        }
コード例 #3
0
        /// <summary>
        /// Creates a new <see cref="ISubscriptionDataSourceReader"/> capable of handling the specified <paramref name="source"/>
        /// </summary>
        /// <param name="source">The subscription data source to create a factory for</param>
        /// <param name="dataCacheProvider">Used to cache data</param>
        /// <param name="config">The configuration of the subscription</param>
        /// <param name="date">The date to be processed</param>
        /// <param name="isLiveMode">True for live mode, false otherwise</param>
        /// <param name="factory">The base data instance factory</param>
        /// <param name="dataProvider">The data provider to use</param>
        /// <returns>A new <see cref="ISubscriptionDataSourceReader"/> that can read the specified <paramref name="source"/></returns>
        public static ISubscriptionDataSourceReader ForSource(SubscriptionDataSource source, IDataCacheProvider dataCacheProvider, SubscriptionDataConfig config, DateTime date, bool isLiveMode, BaseData factory, IDataProvider dataProvider)
        {
            ISubscriptionDataSourceReader reader;

            switch (source.Format)
            {
            case FileFormat.Csv:
                reader = new TextSubscriptionDataSourceReader(dataCacheProvider, config, date, isLiveMode);
                break;

            case FileFormat.UnfoldingCollection:
                reader = new CollectionSubscriptionDataSourceReader(dataCacheProvider, config, date, isLiveMode);
                break;

            case FileFormat.ZipEntryName:
                reader = new ZipEntryNameSubscriptionDataSourceReader(dataCacheProvider, config, date, isLiveMode);
                break;

            case FileFormat.Index:
                return(new IndexSubscriptionDataSourceReader(dataCacheProvider, config, date, isLiveMode, dataProvider));

            case FileFormat.FoldingCollection:
                reader = new BaseDataCollectionAggregatorReader(dataCacheProvider, config, date, isLiveMode);
                break;

            default:
                throw new NotImplementedException("SubscriptionFactory.ForSource(" + source + ") has not been implemented yet.");
            }

            // wire up event handlers for logging missing files
            if (ShowMissingDataLogs && source.TransportMedium == SubscriptionTransportMedium.LocalFile)
            {
                if (!factory.IsSparseData())
                {
                    reader.InvalidSource += (sender, args) => Log.Error($"SubscriptionDataSourceReader.InvalidSource(): File not found: {args.Source.Source}");
                }
            }

            return(reader);
        }