public void Given()
            {
                _timeProvider = new ManualTimeProvider(_referenceUtc);

                _dataSourceReader = new Mock <ISubscriptionDataSourceReader>();
                _dataSourceReader.Setup(dsr => dsr.Read(It.Is <SubscriptionDataSource>(sds =>
                                                                                       sds.Source == "rest.source" &&
                                                                                       sds.TransportMedium == SubscriptionTransportMedium.Rest &&
                                                                                       sds.Format == FileFormat.Csv))
                                        )
                .Returns(Enumerable.Range(0, 100)
                         .Select(i => new RestData
                {
                    EndTime = _referenceLocal.AddSeconds(i)
                }))
                .Verifiable();

                var quoteCurrency = new Cash(CashBook.AccountCurrency, 0, 1);
                var exchangeHours = MarketHoursDatabase.FromDataFolder().GetExchangeHours(Market.USA, Symbols.SPY, SecurityType.Equity);
                var config        = new SubscriptionDataConfig(typeof(RestData), Symbols.SPY, Resolution.Second, TimeZones.NewYork, TimeZones.NewYork, false, false, false);
                var security      = new Equity(Symbols.SPY, exchangeHours, quoteCurrency, SymbolProperties.GetDefault(CashBook.AccountCurrency));
                var request       = new SubscriptionRequest(false, null, security, config, _referenceUtc.AddSeconds(-1), _referenceUtc.AddDays(1));

                var factory = new TestableLiveCustomDataSubscriptionEnumeratorFactory(_timeProvider, _dataSourceReader.Object);

                _enumerator = factory.CreateEnumerator(request, null);
            }
예제 #2
0
            public void Given()
            {
                _timeProvider = new ManualTimeProvider(_referenceUtc);

                _dataSourceReader = new Mock <ISubscriptionDataSourceReader>();
                _dataSourceReader.Setup(dsr => dsr.Read(It.Is <SubscriptionDataSource>(sds =>
                                                                                       sds.Source == "remote.file.source" &&
                                                                                       sds.TransportMedium == SubscriptionTransportMedium.RemoteFile &&
                                                                                       sds.Format == FileFormat.Csv))
                                        )
                .Returns(() => Enumerable.Range(0, 100)
                         .Select(i => new RemoteFileData
                {
                    // include past data
                    EndTime = _referenceLocal.Add(TimeSpan.FromDays(i - (100 - _dataPointsAfterReference - 1)))
                }))
                .Verifiable();

                var quoteCurrency = new Cash(Currencies.USD, 0, 1);
                var exchangeHours = MarketHoursDatabase.FromDataFolder().GetExchangeHours(Market.USA, Symbols.SPY, SecurityType.Equity);
                var config        = new SubscriptionDataConfig(typeof(RemoteFileData), Symbols.SPY, Resolution.Daily, TimeZones.NewYork, TimeZones.NewYork, false, false, false);
                var security      = new Equity(
                    Symbols.SPY,
                    exchangeHours,
                    quoteCurrency,
                    SymbolProperties.GetDefault(Currencies.USD),
                    ErrorCurrencyConverter.Instance,
                    RegisteredSecurityDataTypesProvider.Null
                    );
                var request = new SubscriptionRequest(false, null, security, config, _referenceUtc.AddDays(-2), _referenceUtc.AddDays(1));

                var factory = new TestableLiveCustomDataSubscriptionEnumeratorFactory(_timeProvider, _dataSourceReader.Object);

                _enumerator = factory.CreateEnumerator(request, null);
            }
예제 #3
0
            public void Given()
            {
                _timeProvider = new ManualTimeProvider(_referenceUtc);

                _dataSourceReader = new Mock <ISubscriptionDataSourceReader>();
                _dataSourceReader.Setup(dsr => dsr.Read(It.Is <SubscriptionDataSource>(sds =>
                                                                                       sds.Source == "remote.file.source" &&
                                                                                       sds.TransportMedium == SubscriptionTransportMedium.RemoteFile &&
                                                                                       sds.Format == FileFormat.Csv))
                                        )
                .Returns(() => Enumerable.Range(0, 100)
                         .Select(i => new RemoteFileData
                {
                    // include past data
                    EndTime = _referenceLocal.Add(TimeSpan.FromDays(i - (100 - _dataPointsAfterReference - 1)))
                }))
                .Verifiable();

                var config  = new SubscriptionDataConfig(typeof(RemoteFileData), Symbols.SPY, Resolution.Daily, TimeZones.NewYork, TimeZones.NewYork, false, false, false);
                var request = GetSubscriptionRequest(config, _referenceUtc.AddDays(-2), _referenceUtc.AddDays(1));

                var factory = new TestableLiveCustomDataSubscriptionEnumeratorFactory(_timeProvider, _dataSourceReader.Object);

                _enumerator = factory.CreateEnumerator(request, null);
            }
예제 #4
0
            public void Given()
            {
                _timeProvider = new ManualTimeProvider(_referenceUtc);

                _dataSourceReader = new Mock <ISubscriptionDataSourceReader>();
                _dataSourceReader.Setup(dsr => dsr.Read(It.Is <SubscriptionDataSource>(sds =>
                                                                                       sds.Source == "rest.collection.source" &&
                                                                                       sds.TransportMedium == SubscriptionTransportMedium.Rest &&
                                                                                       sds.Format == FileFormat.UnfoldingCollection))
                                        )
                .Returns(Enumerable.Range(0, 100)
                         .Select(i => new BaseDataCollection(_referenceLocal.AddSeconds(i), Symbols.SPY, Enumerable.Range(0, DataPerTimeStep)
                                                             .Select(_ => new RestCollectionData {
                    EndTime = _referenceLocal.AddSeconds(i)
                })))
                         )
                .Verifiable();

                var config  = new SubscriptionDataConfig(typeof(RestCollectionData), Symbols.SPY, Resolution.Second, TimeZones.NewYork, TimeZones.NewYork, false, false, false);
                var request = GetSubscriptionRequest(config, _referenceUtc.AddSeconds(-4), _referenceUtc.AddDays(1));

                var factory = new TestableLiveCustomDataSubscriptionEnumeratorFactory(_timeProvider, _dataSourceReader.Object);

                _enumerator = factory.CreateEnumerator(request, null);
            }
예제 #5
0
        public void AllowsSpecifyingIntervalCheck(int intervalCheck)
        {
            var referenceLocal = new DateTime(2017, 10, 12);
            var referenceUtc   = new DateTime(2017, 10, 12).ConvertToUtc(TimeZones.NewYork);

            var timeProvider = new ManualTimeProvider(referenceUtc);

            var callCount        = 0;
            var dataSourceReader = new Mock <ISubscriptionDataSourceReader>();

            dataSourceReader.Setup(dsr => dsr.Read(It.Is <SubscriptionDataSource>(sds =>
                                                                                  sds.Source == "local.file.source" &&
                                                                                  sds.TransportMedium == SubscriptionTransportMedium.LocalFile &&
                                                                                  sds.Format == FileFormat.Csv))
                                   )
            .Returns(() => new [] { new LocalFileData {
                                        EndTime = referenceLocal.AddSeconds(++callCount)
                                    } })
            .Verifiable();

            var config  = new SubscriptionDataConfig(typeof(LocalFileData), Symbols.SPY, Resolution.Daily, TimeZones.NewYork, TimeZones.NewYork, false, false, false);
            var request = GetSubscriptionRequest(config, referenceUtc.AddSeconds(-1), referenceUtc.AddDays(1));

            var intervalCalls = intervalCheck == 0 ? (TimeSpan?)null : TimeSpan.FromMinutes(intervalCheck);

            var factory    = new TestableLiveCustomDataSubscriptionEnumeratorFactory(timeProvider, dataSourceReader.Object, intervalCalls);
            var enumerator = factory.CreateEnumerator(request, null);

            Assert.IsTrue(enumerator.MoveNext());
            Assert.IsNotNull(enumerator.Current);
            Assert.AreEqual(referenceLocal.AddSeconds(callCount), enumerator.Current.EndTime);

            VerifyGetSourceInvocationCount(dataSourceReader, 1, "local.file.source", SubscriptionTransportMedium.LocalFile, FileFormat.Csv);

            // time didn't pass so should refresh
            Assert.IsTrue(enumerator.MoveNext());
            Assert.IsNull(enumerator.Current);
            VerifyGetSourceInvocationCount(dataSourceReader, 1, "local.file.source", SubscriptionTransportMedium.LocalFile, FileFormat.Csv);

            var expectedInterval = intervalCalls ?? TimeSpan.FromMinutes(30);

            timeProvider.Advance(expectedInterval.Add(-TimeSpan.FromSeconds(2)));
            Assert.IsTrue(enumerator.MoveNext());
            Assert.IsNull(enumerator.Current);
            VerifyGetSourceInvocationCount(dataSourceReader, 1, "local.file.source", SubscriptionTransportMedium.LocalFile, FileFormat.Csv);

            timeProvider.Advance(TimeSpan.FromSeconds(2));
            Assert.IsTrue(enumerator.MoveNext());
            Assert.IsNotNull(enumerator.Current);
            Assert.AreEqual(referenceLocal.AddSeconds(callCount), enumerator.Current.EndTime);
            VerifyGetSourceInvocationCount(dataSourceReader, 2, "local.file.source", SubscriptionTransportMedium.LocalFile, FileFormat.Csv);
        }