/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="UniverseSelection"/> class /// </summary> /// <param name="algorithm">The algorithm to add securities to</param> /// <param name="securityService">The security service</param> /// <param name="dataPermissionManager">The data permissions manager</param> /// <param name="dataProvider">The data provider to use</param> /// <param name="internalConfigResolution">The resolution to use for internal configuration</param> public UniverseSelection( IAlgorithm algorithm, ISecurityService securityService, IDataPermissionManager dataPermissionManager, IDataProvider dataProvider, Resolution internalConfigResolution = Resolution.Minute) { _dataProvider = dataProvider; _algorithm = algorithm; _securityService = securityService; _dataPermissionManager = dataPermissionManager; _pendingRemovalsManager = new PendingRemovalsManager(algorithm.Transactions); _currencySubscriptionDataConfigManager = new CurrencySubscriptionDataConfigManager(algorithm.Portfolio.CashBook, algorithm.Securities, algorithm.SubscriptionManager, _securityService, dataPermissionManager.GetResolution(Resolution.Minute)); // TODO: next step is to merge currency internal subscriptions under the same 'internal manager' instance and we could move this directly into the DataManager class _internalSubscriptionManager = new InternalSubscriptionManager(_algorithm, internalConfigResolution); }
/// <summary> /// Initializes a new instance of the <see cref="UniverseSelection"/> class /// </summary> /// <param name="algorithm">The algorithm to add securities to</param> /// <param name="securityService">The security service</param> /// <param name="dataPermissionManager">The data permissions manager</param> public UniverseSelection( IAlgorithm algorithm, ISecurityService securityService, IDataPermissionManager dataPermissionManager) { _algorithm = algorithm; _securityService = securityService; _dataPermissionManager = dataPermissionManager; _pendingRemovalsManager = new PendingRemovalsManager(algorithm.Transactions); _currencySubscriptionDataConfigManager = new CurrencySubscriptionDataConfigManager(algorithm.Portfolio.CashBook, algorithm.Securities, algorithm.SubscriptionManager, _securityService, dataPermissionManager.GetResolution(Resolution.Minute)); }