/// <summary> /// Adds a new <see cref="Subscription"/> to provide data for the specified security. /// </summary> /// <param name="request">Defines the <see cref="SubscriptionRequest"/> to be added</param> /// <returns>True if the subscription was created and added successfully, false otherwise</returns> public bool AddSubscription(SubscriptionRequest request) { Subscription subscription; if (DataFeedSubscriptions.TryGetValue(request.Configuration, out subscription)) { // duplicate subscription request return(subscription.AddSubscriptionRequest(request)); } subscription = _dataFeed.CreateSubscription(request); if (subscription == null) { Log.Trace($"DataManager.AddSubscription(): Unable to add subscription for: {request.Configuration}"); // subscription will be null when there's no tradeable dates for the security between the requested times, so // don't even try to load the data return(false); } if (_liveMode) { OnSubscriptionAdded(subscription); } LiveDifferentiatedLog($"DataManager.AddSubscription(): Added {request.Configuration}." + $" Start: {request.StartTimeUtc}. End: {request.EndTimeUtc}"); return(DataFeedSubscriptions.TryAdd(subscription)); }
/// <summary> /// Removes the subscription from the data feed, if it exists /// </summary> /// <param name="configuration">The configuration of the subscription to remove</param> /// <returns>True if the subscription was successfully removed, false otherwise</returns> public bool RemoveSubscription(SubscriptionDataConfig configuration) { // remove the subscription from our collection, if it exists Subscription subscription; if (_subscriptions.TryGetValue(configuration, out subscription)) { if (!_subscriptions.TryRemove(configuration, out subscription)) { Log.Error("FileSystemDataFeed.RemoveSubscription(): Unable to remove: " + configuration); return(false); } // if the security is no longer a member of the universe, then mark the subscription properly if (!subscription.Universe.Members.ContainsKey(configuration.Symbol)) { subscription.MarkAsRemovedFromUniverse(); } subscription.Dispose(); Log.Debug("FileSystemDataFeed.RemoveSubscription(): Removed " + configuration); UpdateFillForwardResolution(); } return(true); }
/// <summary> /// Removes the subscription from the data feed, if it exists /// </summary> /// <param name="configuration">The configuration of the subscription to remove</param> /// <returns>True if the subscription was successfully removed, false otherwise</returns> public bool RemoveSubscription(SubscriptionDataConfig configuration) { // remove the subscription from our collection, if it exists Subscription subscription; if (_subscriptions.TryGetValue(configuration, out subscription)) { // don't remove universe subscriptions immediately, instead mark them as disposed // so we can turn the crank one more time to ensure we emit security changes properly if (subscription.IsUniverseSelectionSubscription && subscription.Universe.DisposeRequested) { // subscription syncer will dispose the universe AFTER we've run selection a final time // and then will invoke SubscriptionFinished which will remove the universe subscription return(false); } if (!_subscriptions.TryRemove(configuration, out subscription)) { Log.Error("FileSystemDataFeed.RemoveSubscription(): Unable to remove: " + configuration); return(false); } // if the security is no longer a member of the universe, then mark the subscription properly // universe may be null for internal currency conversion feeds // TODO : Put currency feeds in their own internal universe if (subscription.Universe != null && !subscription.Universe.Members.ContainsKey(configuration.Symbol)) { subscription.MarkAsRemovedFromUniverse(); } subscription.Dispose(); Log.Debug("FileSystemDataFeed.RemoveSubscription(): Removed " + configuration); } return(true); }
/// <summary> /// Adds a new <see cref="Subscription"/> to provide data for the specified security. /// </summary> /// <param name="request">Defines the <see cref="SubscriptionRequest"/> to be added</param> /// <returns>True if the subscription was created and added successfully, false otherwise</returns> public bool AddSubscription(SubscriptionRequest request) { // guarantee the configuration is present in our config collection // this is related to GH issue 3877: where we added a configuration which we also removed _subscriptionManagerSubscriptions.TryAdd(request.Configuration, request.Configuration); Subscription subscription; if (DataFeedSubscriptions.TryGetValue(request.Configuration, out subscription)) { // duplicate subscription request subscription.AddSubscriptionRequest(request); // only result true if the existing subscription is internal, we actually added something from the users perspective return(subscription.Configuration.IsInternalFeed); } // before adding the configuration to the data feed let's assert it's valid _dataPermissionManager.AssertConfiguration(request.Configuration, request.StartTimeLocal, request.EndTimeLocal); subscription = _dataFeed.CreateSubscription(request); if (subscription == null) { Log.Trace($"DataManager.AddSubscription(): Unable to add subscription for: {request.Configuration}"); // subscription will be null when there's no tradeable dates for the security between the requested times, so // don't even try to load the data return(false); } if (_liveMode) { OnSubscriptionAdded(subscription); Log.Trace($"DataManager.AddSubscription(): Added {request.Configuration}." + $" Start: {request.StartTimeUtc}. End: {request.EndTimeUtc}"); } else if (Log.DebuggingEnabled) { // for performance lets not create the message string if debugging is not enabled // this can be executed many times and its in the algorithm thread Log.Debug($"DataManager.AddSubscription(): Added {request.Configuration}." + $" Start: {request.StartTimeUtc}. End: {request.EndTimeUtc}"); } return(DataFeedSubscriptions.TryAdd(subscription)); }
/// <summary> /// Adds a new <see cref="Subscription"/> to provide data for the specified security. /// </summary> /// <param name="request">Defines the <see cref="SubscriptionRequest"/> to be added</param> /// <returns>True if the subscription was created and added successfully, false otherwise</returns> public bool AddSubscription(SubscriptionRequest request) { Subscription subscription; if (DataFeedSubscriptions.TryGetValue(request.Configuration, out subscription)) { // duplicate subscription request return(subscription.AddSubscriptionRequest(request)); } subscription = _dataFeed.CreateSubscription(request); if (subscription == null) { Log.Trace($"DataManager.AddSubscription(): Unable to add subscription for: {request.Configuration}"); // subscription will be null when there's no tradeable dates for the security between the requested times, so // don't even try to load the data return(false); } if (_liveMode) { OnSubscriptionAdded(subscription); Log.Trace($"DataManager.AddSubscription(): Added {request.Configuration}." + $" Start: {request.StartTimeUtc}. End: {request.EndTimeUtc}"); } else if (Log.DebuggingEnabled) { // for performance lets not create the message string if debugging is not enabled // this can be executed many times and its in the algorithm thread Log.Debug($"DataManager.AddSubscription(): Added {request.Configuration}." + $" Start: {request.StartTimeUtc}. End: {request.EndTimeUtc}"); } return(DataFeedSubscriptions.TryAdd(subscription)); }
/// <summary> /// Removes the subscription from the data feed, if it exists /// </summary> /// <param name="configuration">The configuration of the subscription to remove</param> /// <returns>True if the subscription was successfully removed, false otherwise</returns> public bool RemoveSubscription(SubscriptionDataConfig configuration) { // remove the subscription from our collection, if it exists Subscription subscription; if (_subscriptions.TryGetValue(configuration, out subscription)) { if (!_subscriptions.TryRemove(configuration, out subscription)) { Log.Error("FileSystemDataFeed.RemoveSubscription(): Unable to remove: " + configuration); return(false); } subscription.Dispose(); Log.Debug("FileSystemDataFeed.RemoveSubscription(): Removed " + configuration); UpdateFillForwardResolution(); } return(true); }