Beispiel #1
0
        /// <summary>
        /// Will add any pending internal currency subscriptions
        /// </summary>
        /// <param name="utcStart">The current date time in utc</param>
        /// <returns>Will return true if any subscription was added</returns>
        public bool AddPendingInternalDataFeeds(DateTime utcStart)
        {
            var added = false;

            if (!_initializedSecurityBenchmark)
            {
                _initializedSecurityBenchmark = true;

                var securityBenchmark = _algorithm.Benchmark as SecurityBenchmark;
                if (securityBenchmark != null)
                {
                    var dataConfig = _algorithm.SubscriptionManager.SubscriptionDataConfigService.Add(
                        securityBenchmark.Security.Symbol,
                        _dataPermissionManager.GetResolution(_algorithm.LiveMode ? Resolution.Minute : Resolution.Hour),
                        isInternalFeed: true,
                        fillForward: false).First();

                    // we want to start from the previous tradable bar so the benchmark security
                    // never has 0 price
                    var previousTradableBar = Time.GetStartTimeForTradeBars(
                        securityBenchmark.Security.Exchange.Hours,
                        utcStart.ConvertFromUtc(securityBenchmark.Security.Exchange.TimeZone),
                        _algorithm.LiveMode ? Time.OneMinute : Time.OneDay,
                        1,
                        false,
                        dataConfig.DataTimeZone).ConvertToUtc(securityBenchmark.Security.Exchange.TimeZone);

                    if (dataConfig != null)
                    {
                        added |= _dataManager.AddSubscription(new SubscriptionRequest(
                                                                  false,
                                                                  null,
                                                                  securityBenchmark.Security,
                                                                  dataConfig,
                                                                  previousTradableBar,
                                                                  _algorithm.EndDate.ConvertToUtc(_algorithm.TimeZone)));

                        Log.Trace($"UniverseSelection.AddPendingInternalDataFeeds(): Adding internal benchmark data feed {dataConfig}");
                    }
                }
            }

            if (_currencySubscriptionDataConfigManager.UpdatePendingSubscriptionDataConfigs(_algorithm.BrokerageModel))
            {
                foreach (var subscriptionDataConfig in _currencySubscriptionDataConfigManager
                         .GetPendingSubscriptionDataConfigs())
                {
                    var security = _algorithm.Securities[subscriptionDataConfig.Symbol];
                    added |= _dataManager.AddSubscription(new SubscriptionRequest(
                                                              false,
                                                              null,
                                                              security,
                                                              subscriptionDataConfig,
                                                              utcStart,
                                                              _algorithm.EndDate.ConvertToUtc(_algorithm.TimeZone)));
                }
            }
            return(added);
        }
Beispiel #2
0
        /// <summary>
        /// Will add any pending internal currency subscriptions
        /// </summary>
        /// <param name="utcStart">The current date time in utc</param>
        /// <returns>Will return true if any subscription was added</returns>
        public bool AddPendingCurrencyDataFeeds(DateTime utcStart)
        {
            var added = false;

            if (_currencySubscriptionDataConfigManager.UpdatePendingSubscriptionDataConfigs())
            {
                foreach (var subscriptionDataConfig in _currencySubscriptionDataConfigManager
                         .GetPendingSubscriptionDataConfigs())
                {
                    var security = _algorithm.Securities[subscriptionDataConfig.Symbol];
                    added |= _dataManager.AddSubscription(new SubscriptionRequest(
                                                              false,
                                                              null,
                                                              security,
                                                              subscriptionDataConfig,
                                                              utcStart,
                                                              _algorithm.EndDate.ConvertToUtc(_algorithm.TimeZone)));
                }
            }
            return(added);
        }
Beispiel #3
0
        /// <summary>
        /// Will add any pending internal currency subscriptions
        /// </summary>
        /// <param name="utcStart">The current date time in utc</param>
        /// <returns>Will return true if any subscription was added</returns>
        public bool AddPendingInternalDataFeeds(DateTime utcStart)
        {
            var added = false;

            if (!_initializedSecurityBenchmark)
            {
                _initializedSecurityBenchmark = true;

                var securityBenchmark = _algorithm.Benchmark as SecurityBenchmark;
                if (securityBenchmark != null)
                {
                    var resolution = _algorithm.LiveMode ? Resolution.Minute : Resolution.Hour;

                    // Check that the tradebar subscription we are using can support this resolution GH #5893
                    var subscriptionType = _algorithm.SubscriptionManager.SubscriptionDataConfigService.LookupSubscriptionConfigDataTypes(securityBenchmark.Security.Type, resolution, securityBenchmark.Security.Symbol.IsCanonical()).First();
                    var baseInstance     = subscriptionType.Item1.GetBaseDataInstance();
                    baseInstance.Symbol = securityBenchmark.Security.Symbol;
                    var supportedResolutions = baseInstance.SupportedResolutions();
                    if (!supportedResolutions.Contains(resolution))
                    {
                        resolution = supportedResolutions.OrderByDescending(x => x).First();
                    }

                    var subscriptionList = new List <Tuple <Type, TickType> >()
                    {
                        subscriptionType
                    };
                    var dataConfig = _algorithm.SubscriptionManager.SubscriptionDataConfigService.Add(
                        securityBenchmark.Security.Symbol,
                        resolution,
                        isInternalFeed: true,
                        fillForward: false,
                        subscriptionDataTypes: subscriptionList
                        ).First();

                    // we want to start from the previous tradable bar so the benchmark security
                    // never has 0 price
                    var previousTradableBar = Time.GetStartTimeForTradeBars(
                        securityBenchmark.Security.Exchange.Hours,
                        utcStart.ConvertFromUtc(securityBenchmark.Security.Exchange.TimeZone),
                        _algorithm.LiveMode ? Time.OneMinute : Time.OneDay,
                        1,
                        false,
                        dataConfig.DataTimeZone).ConvertToUtc(securityBenchmark.Security.Exchange.TimeZone);

                    if (dataConfig != null)
                    {
                        added |= _dataManager.AddSubscription(new SubscriptionRequest(
                                                                  false,
                                                                  null,
                                                                  securityBenchmark.Security,
                                                                  dataConfig,
                                                                  previousTradableBar,
                                                                  _algorithm.EndDate.ConvertToUtc(_algorithm.TimeZone)));

                        Log.Trace($"UniverseSelection.AddPendingInternalDataFeeds(): Adding internal benchmark data feed {dataConfig}");
                    }
                }
            }

            if (_currencySubscriptionDataConfigManager.UpdatePendingSubscriptionDataConfigs(_algorithm.BrokerageModel))
            {
                foreach (var subscriptionDataConfig in _currencySubscriptionDataConfigManager
                         .GetPendingSubscriptionDataConfigs())
                {
                    var security = _algorithm.Securities[subscriptionDataConfig.Symbol];
                    added |= _dataManager.AddSubscription(new SubscriptionRequest(
                                                              false,
                                                              null,
                                                              security,
                                                              subscriptionDataConfig,
                                                              utcStart,
                                                              _algorithm.EndDate.ConvertToUtc(_algorithm.TimeZone)));
                }
            }
            return(added);
        }