/// <summary>
        /// Creates an enumerator to read the specified request
        /// </summary>
        /// <param name="request">The subscription request to be read</param>
        /// <param name="dataFileProvider">Provider used to get data when it is not present on disk</param>
        /// <returns>An enumerator reading the subscription request</returns>
        public IEnumerator <BaseData> CreateEnumerator(SubscriptionRequest request, IDataFileProvider dataFileProvider)
        {
            if (_isLiveMode)
            {
                var localTime = request.StartTimeUtc.ConvertFromUtc(request.Configuration.ExchangeTimeZone);

                // loading the list of option contract and converting them into zip entries
                var symbols    = _symbolUniverse.LookupSymbols(request.Security.Symbol.Underlying.ToString(), request.Security.Type);
                var zipEntries = symbols.Select(x => new ZipEntryName {
                    Time = localTime, Symbol = x
                } as BaseData).ToList();

                // creating trade bar builder enumerator to model underlying price change
                var underlyingEnumerator = new TradeBarBuilderEnumerator(request.Configuration.Increment, request.Security.Exchange.TimeZone, _timeProvider);

                // configuring the enumerator
                var subscriptionConfiguration = GetSubscriptionConfigurations(request).First();
                var subscriptionRequest       = new SubscriptionRequest(request, configuration: subscriptionConfiguration);
                var configuredEnumerator      = _enumeratorConfigurator(subscriptionRequest, underlyingEnumerator);

                return(new DataQueueOptionChainUniverseDataCollectionEnumerator(request.Security.Symbol, configuredEnumerator, zipEntries));
            }
            else
            {
                var factory = new BaseDataSubscriptionEnumeratorFactory(_mapFileResolver, _factorFileProvider);

                var enumerators = GetSubscriptionConfigurations(request)
                                  .Select(c => new SubscriptionRequest(request, configuration: c))
                                  .Select(sr => _enumeratorConfigurator(request, factory.CreateEnumerator(sr, dataFileProvider)));

                var sync = new SynchronizingEnumerator(enumerators);
                return(new OptionChainUniverseDataCollectionEnumerator(sync, request.Security.Symbol));
            }
        }
Пример #2
0
        /// <summary>
        /// Advances the enumerator to the next element of the collection.
        /// </summary>
        /// <returns>
        /// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
        /// </returns>
        public bool MoveNext()
        {
            Underlying.MoveNext();

            if (Underlying.Current == null)
            {
                Current = null;
                return(true);
            }

            if (!_needNewCurrent)
            {
                // refresh on date change (in exchange time zone)
                _needNewCurrent = _timeProvider.GetUtcNow().ConvertFromUtc(_subscriptionRequest.Configuration.ExchangeTimeZone).Date != _lastEmitTime.Date;
            }

            if (_needNewCurrent)
            {
                var localTime = _timeProvider.GetUtcNow()
                                .RoundDown(_subscriptionRequest.Configuration.Increment)
                                .ConvertFromUtc(_subscriptionRequest.Configuration.ExchangeTimeZone);

                // loading the list of futures contracts and converting them into zip entries
                var symbols    = _universeProvider.LookupSymbols(_subscriptionRequest.Security.Symbol.ID.Symbol, _subscriptionRequest.Security.Type);
                var zipEntries = symbols.Select(x => new ZipEntryName {
                    Time = localTime, Symbol = x
                } as BaseData).ToList();
                _currentData = new OptionChainUniverseDataCollection
                {
                    Symbol     = _subscriptionRequest.Security.Symbol,
                    Underlying = Underlying.Current,
                    Data       = zipEntries,
                    Time       = localTime,
                    EndTime    = localTime
                };

                _lastEmitTime = localTime;

                Current         = _currentData;
                _needNewCurrent = false;
            }
            else
            {
                if (Current == null)
                {
                    Current = _currentData;
                }

                Current.Underlying = Underlying.Current;
                Current.Time       = Underlying.Current.EndTime;
                Current.EndTime    = Underlying.Current.EndTime;

                _lastEmitTime = Current.EndTime;
            }

            return(true);
        }
        /// <summary>
        /// Advances the enumerator to the next element of the collection.
        /// </summary>
        /// <returns>
        /// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
        /// </returns>
        public bool MoveNext()
        {
            if (!_needNewCurrent)
            {
                // refresh on date change (in exchange time zone)
                _needNewCurrent = _timeProvider.GetUtcNow().ConvertFromUtc(_subscriptionRequest.Configuration.ExchangeTimeZone).Date != _lastEmitTime.Date;
            }

            if (_needNewCurrent)
            {
                if (!_universeProvider.CanPerformSelection())
                {
                    Current = null;
                    return(true);
                }

                var localTime = _timeProvider.GetUtcNow()
                                .RoundDown(_subscriptionRequest.Configuration.Increment)
                                .ConvertFromUtc(_subscriptionRequest.Configuration.ExchangeTimeZone);

                // loading the list of futures contracts and converting them into zip entries
                var symbols    = _universeProvider.LookupSymbols(_subscriptionRequest.Security.Symbol, false);
                var zipEntries = symbols.Select(x => new ZipEntryName {
                    Time = localTime, Symbol = x
                } as BaseData).ToList();
                var current = new BaseDataCollection
                {
                    Symbol  = _subscriptionRequest.Security.Symbol,
                    Data    = zipEntries,
                    Time    = localTime,
                    EndTime = localTime
                };

                _lastEmitTime = localTime;

                Log.Trace($"DataQueueFuturesChainUniverseDataCollectionEnumerator({current.Symbol}): Emitting data point: {current.EndTime}. Count: {current.Data.Count}");

                Current         = current;
                _needNewCurrent = false;
            }
            else
            {
                Current = null;
            }

            return(true);
        }
Пример #4
0
        /// <summary>
        /// Creates an enumerator to read the specified request
        /// </summary>
        /// <param name="request">The subscription request to be read</param>
        /// <param name="dataProvider">Provider used to get data when it is not present on disk</param>
        /// <returns>An enumerator reading the subscription request</returns>
        public IEnumerator <BaseData> CreateEnumerator(SubscriptionRequest request, IDataProvider dataProvider)
        {
            if (_isLiveMode)
            {
                var localTime = request.StartTimeUtc.ConvertFromUtc(request.Configuration.ExchangeTimeZone);

                // loading the list of futures contracts and converting them into zip entries
                var symbols    = _symbolUniverse.LookupSymbols(request.Security.Symbol.ID.Symbol, request.Security.Type);
                var zipEntries = symbols.Select(x => new ZipEntryName {
                    Time = localTime, Symbol = x
                } as BaseData).ToList();

                var underlyingEnumerator = new TradeBarBuilderEnumerator(request.Configuration.Increment, request.Security.Exchange.TimeZone, _timeProvider);
                underlyingEnumerator.ProcessData(new Tick {
                    Value = 0
                });

                // configuring the enumerator
                var subscriptionConfiguration = GetSubscriptionConfigurations(request).First();
                var subscriptionRequest       = new SubscriptionRequest(request, configuration: subscriptionConfiguration);
                var configuredEnumerator      = _enumeratorConfigurator(subscriptionRequest, underlyingEnumerator);

                return(new DataQueueFuturesChainUniverseDataCollectionEnumerator(request.Security.Symbol, configuredEnumerator, zipEntries));
            }
            else
            {
                var factory = new BaseDataSubscriptionEnumeratorFactory(_isLiveMode);

                var enumerators = GetSubscriptionConfigurations(request)
                                  .Select(c => new SubscriptionRequest(request, configuration: c))
                                  .Select(sr => _enumeratorConfigurator(request, factory.CreateEnumerator(sr, dataProvider)));

                var sync = new SynchronizingEnumerator(enumerators);
                return(new FuturesChainUniverseDataCollectionAggregatorEnumerator(sync, request.Security.Symbol));
            }
        }