예제 #1
0
파일: DataManager.cs 프로젝트: kbank14/Lean
        /// <summary>
        /// Removes the <see cref="Subscription"/>, if it exists
        /// </summary>
        /// <param name="configuration">The <see cref="SubscriptionDataConfig"/> of the subscription to remove</param>
        /// <param name="universe">Universe requesting to remove <see cref="Subscription"/>.
        /// Default value, null, will remove all universes</param>
        /// <returns>True if the subscription was successfully removed, false otherwise</returns>
        public bool RemoveSubscription(SubscriptionDataConfig configuration, Universe universe = null)
        {
            // remove the subscription from our collection, if it exists
            Subscription subscription;

            if (DataFeedSubscriptions.TryGetValue(configuration, out subscription))
            {
                // we remove the subscription when there are no other requests left
                if (subscription.RemoveSubscriptionRequest(universe))
                {
                    if (!DataFeedSubscriptions.TryRemove(configuration, out subscription))
                    {
                        Log.Error($"DataManager.RemoveSubscription(): Unable to remove {configuration}");
                        return(false);
                    }

                    _dataFeed.RemoveSubscription(subscription);

                    if (_liveMode)
                    {
                        OnSubscriptionRemoved(subscription);
                    }

                    subscription.Dispose();

                    RemoveSubscriptionDataConfig(subscription);

                    if (_liveMode)
                    {
                        Log.Trace($"DataManager.RemoveSubscription(): Removed {configuration}");
                    }
                    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.RemoveSubscription(): Removed {configuration}");
                    }
                    return(true);
                }
            }
            else if (universe != null)
            {
                // a universe requested removal of a subscription which wasn't present anymore, this can happen when a subscription ends
                // it will get removed from the data feed subscription list, but the configuration will remain until the universe removes it
                // why? the effect I found is that the fill models are using these subscriptions to determine which data they could use
                SubscriptionDataConfig config;
                _subscriptionManagerSubscriptions.TryRemove(configuration, out config);
            }
            return(false);
        }
예제 #2
0
        /// <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)
        {
            Subscription subscription;

            if (!_subscriptions.TryRemove(configuration, out subscription))
            {
                Log.Error("FileSystemDataFeed.RemoveSubscription(): Unable to remove: " + configuration.ToString());
                return(false);
            }

            subscription.Dispose();
            Log.Debug("FileSystemDataFeed.RemoveSubscription(): Removed " + configuration.ToString());

            UpdateFillForwardResolution();

            return(true);
        }
예제 #3
0
        /// <summary>
        /// Removes the <see cref="Subscription"/>, if it exists
        /// </summary>
        /// <param name="configuration">The <see cref="SubscriptionDataConfig"/> of the subscription to remove</param>
        /// <param name="universe">Universe requesting to remove <see cref="Subscription"/>.
        /// Default value, null, will remove all universes</param>
        /// <returns>True if the subscription was successfully removed, false otherwise</returns>
        public bool RemoveSubscription(SubscriptionDataConfig configuration, Universe universe = null)
        {
            // remove the subscription from our collection, if it exists
            Subscription subscription;

            if (DataFeedSubscriptions.TryGetValue(configuration, out subscription))
            {
                // we remove the subscription when there are no other requests left
                if (subscription.RemoveSubscriptionRequest(universe))
                {
                    if (!DataFeedSubscriptions.TryRemove(configuration, out subscription))
                    {
                        Log.Error($"DataManager.RemoveSubscription(): Unable to remove {configuration}");
                        return(false);
                    }

                    _dataFeed.RemoveSubscription(subscription);

                    if (_liveMode)
                    {
                        OnSubscriptionRemoved(subscription);
                    }

                    subscription.Dispose();

                    RemoveSubscriptionDataConfig(subscription);

                    if (_liveMode)
                    {
                        Log.Trace($"DataManager.RemoveSubscription(): Removed {configuration}");
                    }
                    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.RemoveSubscription(): Removed {configuration}");
                    }
                    return(true);
                }
            }
            return(false);
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
        /// <summary>
        /// Removes the <see cref="Subscription"/>, if it exists
        /// </summary>
        /// <param name="configuration">The <see cref="SubscriptionDataConfig"/> 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 (DataFeedSubscriptions.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 (!DataFeedSubscriptions.TryRemove(configuration, out subscription))
                {
                    Log.Error($"DataManager.RemoveSubscription(): Unable to remove {configuration}");
                    return(false);
                }

                _dataFeed.RemoveSubscription(subscription);

                // 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($"DataManager.RemoveSubscription(): Removed {configuration}");
                return(true);
            }

            return(false);
        }
예제 #6
0
        /// <summary>
        /// Removes the <see cref="Subscription"/>, if it exists
        /// </summary>
        /// <param name="configuration">The <see cref="SubscriptionDataConfig"/> of the subscription to remove</param>
        /// <param name="universe">Universe requesting to remove <see cref="Subscription"/>.
        /// Default value, null, will remove all universes</param>
        /// <returns>True if the subscription was successfully removed, false otherwise</returns>
        public bool RemoveSubscription(SubscriptionDataConfig configuration, Universe universe = null)
        {
            // remove the subscription from our collection, if it exists
            Subscription subscription;

            if (DataFeedSubscriptions.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.Universes.Single().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);
                }

                // we remove the subscription when there are no other requests left
                if (subscription.RemoveSubscriptionRequest(universe))
                {
                    if (!DataFeedSubscriptions.TryRemove(configuration, out subscription))
                    {
                        Log.Error($"DataManager.RemoveSubscription(): Unable to remove {configuration}");
                        return(false);
                    }

                    _dataFeed.RemoveSubscription(subscription);

                    subscription.Dispose();

                    RemoveSubscriptionDataConfig(configuration);

                    LiveDifferentiatedLog($"DataManager.RemoveSubscription(): Removed {configuration}");
                    return(true);
                }
            }
            return(false);
        }