Exemple #1
0
        /// <summary>
        /// Helper method to determine if the symbol associated with the requested configuration is expired or not
        /// </summary>
        /// <remarks>This is useful during warmup where we can be requested to add some already expired asset. We want to skip sending it
        /// to our live <see cref="_dataQueueHandler"/> instance to avoid explosions. But we do want to add warmup enumerators</remarks>
        private bool IsExpired(SubscriptionDataConfig dataConfig)
        {
            var mapFile       = _mapFileProvider.ResolveMapFile(dataConfig);
            var delistingDate = dataConfig.Symbol.GetDelistingDate(mapFile);

            return(_timeProvider.GetUtcNow().Date > delistingDate.ConvertToUtc(dataConfig.ExchangeTimeZone));
        }
Exemple #2
0
        /// <summary>
        /// Performs universe selection based on the symbol mapping
        /// </summary>
        /// <param name="utcTime">The current utc time</param>
        /// <param name="data">Empty data</param>
        /// <returns>The symbols to use</returns>
        public override IEnumerable <Symbol> SelectSymbols(DateTime utcTime, BaseDataCollection data)
        {
            yield return(_security.Symbol.Canonical);

            var mapFile = _mapFileProvider.ResolveMapFile(new SubscriptionDataConfig(Configuration,
                                                                                     dataMappingMode: UniverseSettings.DataMappingMode,
                                                                                     symbol: _security.Symbol.Canonical));

            var mappedSymbol = mapFile.GetMappedSymbol(utcTime.ConvertFromUtc(_security.Exchange.TimeZone));

            if (!string.IsNullOrEmpty(mappedSymbol) && mappedSymbol != _mappedSymbol)
            {
                if (_currentSymbol != null)
                {
                    // let's emit the old and new for the mapping date
                    yield return(_currentSymbol);
                }
                _mappedSymbol = mappedSymbol;

                _currentSymbol = _security.Symbol.Canonical
                                 .UpdateMappedSymbol(mappedSymbol, Configuration.ContractDepthOffset)
                                 .Underlying;
            }

            if (_currentSymbol != null)
            {
                ((IContinuousSecurity)_security).Mapped = _currentSymbol;
                yield return(_currentSymbol);
            }
        }
 /// <summary>
 /// Initializes this instance
 /// </summary>
 /// <param name="config">The <see cref="SubscriptionDataConfig"/></param>
 /// <param name="factorFileProvider">The factor file provider to use</param>
 /// <param name="mapFileProvider">The <see cref="Data.Auxiliary.MapFile"/> provider to use</param>
 /// <param name="startTime">Start date for the data request</param>
 public void Initialize(
     SubscriptionDataConfig config,
     IFactorFileProvider factorFileProvider,
     IMapFileProvider mapFileProvider,
     DateTime startTime)
 {
     _config     = config;
     _mapFile    = mapFileProvider.ResolveMapFile(_config);
     _factorFile = factorFileProvider.Get(_config.Symbol) as CorporateFactorProvider;
 }
        /// <summary>
        /// Initializes this instance
        /// </summary>
        /// <param name="config">The <see cref="SubscriptionDataConfig"/></param>
        /// <param name="factorFileProvider">The factor file provider to use</param>
        /// <param name="mapFileProvider">The <see cref="Data.Auxiliary.MapFile"/> provider to use</param>
        /// <param name="startTime">Start date for the data request</param>
        public virtual void Initialize(
            SubscriptionDataConfig config,
            IFactorFileProvider factorFileProvider,
            IMapFileProvider mapFileProvider,
            DateTime startTime)
        {
            _config = config;
            var mapFile = mapFileProvider.ResolveMapFile(_config);

            DelistingDate = new ReferenceWrapper <DateTime>(config.Symbol.GetDelistingDate(mapFile));
        }
Exemple #5
0
        /// <summary>
        /// Initializes the <see cref="SubscriptionDataReader"/> instance
        /// </summary>
        /// <remarks>Should be called after all consumers of <see cref="NewTradableDate"/> event are set,
        /// since it will produce events.</remarks>
        public void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            //Save the type of data we'll be getting from the source.
            try
            {
                _dataFactory = _config.GetBaseDataInstance();
            }
            catch (ArgumentException exception)
            {
                OnInvalidConfigurationDetected(new InvalidConfigurationDetectedEventArgs(_config.Symbol, exception.Message));
                _endOfStream = true;
                return;
            }

            // If Tiingo data, set the access token in data factory
            var tiingo = _dataFactory as TiingoPrice;

            if (tiingo != null)
            {
                if (!Tiingo.IsAuthCodeSet)
                {
                    Tiingo.SetAuthCode(Config.Get("tiingo-auth-token"));
                }
            }

            // load up the map files for equities, options, and custom data if it supports it.
            // Only load up factor files for equities
            if (_dataFactory.RequiresMapping())
            {
                try
                {
                    var mapFile = _mapFileProvider.ResolveMapFile(_config);

                    // only take the resolved map file if it has data, otherwise we'll use the empty one we defined above
                    if (mapFile.Any())
                    {
                        _mapFile = mapFile;
                    }

                    if (_config.PricesShouldBeScaled())
                    {
                        var factorFile = _factorFileProvider.Get(_config.Symbol);
                        _hasScaleFactors = factorFile != null;
                        if (_hasScaleFactors)
                        {
                            _factorFile = factorFile;

                            // if factor file has minimum date, update start period if before minimum date
                            if (!_isLiveMode && _factorFile != null && _factorFile.FactorFileMinimumDate.HasValue)
                            {
                                if (_periodStart < _factorFile.FactorFileMinimumDate.Value)
                                {
                                    _periodStart = _factorFile.FactorFileMinimumDate.Value;

                                    OnNumericalPrecisionLimited(
                                        new NumericalPrecisionLimitedEventArgs(_config.Symbol,
                                                                               $"[{_config.Symbol.Value}, {_factorFile.FactorFileMinimumDate.Value.ToShortDateString()}]"));
                                }
                            }
                        }

                        if (_periodStart < mapFile.FirstDate)
                        {
                            _periodStart = mapFile.FirstDate;

                            OnStartDateLimited(
                                new StartDateLimitedEventArgs(_config.Symbol,
                                                              $"[{_config.Symbol.Value}," +
                                                              $" {mapFile.FirstDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)}]"));
                        }
                    }
                }
                catch (Exception err)
                {
                    Log.Error(err, "Fetching Price/Map Factors: " + _config.Symbol.ID + ": ");
                }
            }

            _factorFile ??= _config.Symbol.GetEmptyFactorFile();
            _mapFile ??= new MapFile(_config.Symbol.Value, Enumerable.Empty <MapFileRow>());

            _delistingDate = _config.Symbol.GetDelistingDate(_mapFile);

            // adding a day so we stop at EOD
            _delistingDate = _delistingDate.AddDays(1);

            UpdateDataEnumerator(true);

            _initialized = true;
        }
 private string GetMappedSymbol(SubscriptionDataConfig config, DateTime date)
 {
     return(_mapFileProvider.ResolveMapFile(config).GetMappedSymbol(date, config.MappedSymbol));
 }
Exemple #7
0
 /// <summary>
 /// Initializes the map file to use
 /// </summary>
 protected void InitializeMapFile()
 {
     MapFile = _mapFileProvider.ResolveMapFile(Config);
 }