/// <summary>
        /// Removes the subscription from the data feed, if it exists
        /// </summary>
        /// <param name="security">The security to remove subscriptions for</param>
        public void RemoveSubscription(Security security)
        {
            var symbols = BuildTypeSymbolList(new[] { security });

            _dataQueue.Unsubscribe(_job, symbols);

            LiveSubscription subscription;

            _subscriptions.TryRemove(new SymbolSecurityType(security), out subscription);
        }
Beispiel #2
0
 /// <summary>
 /// Trigger the live trading datafeed thread to abort and stop looping.
 /// </summary>
 public void Exit()
 {
     lock (_lock)
     {
         // Unsubscribe from these symbols
         _dataQueue.Unsubscribe(_job, BuildTypeSymbolList(_algorithm));
         _exitTriggered = true;
         PurgeData();
     }
 }
Beispiel #3
0
 /// <summary>
 /// Trigger the live trading datafeed thread to abort and stop looping.
 /// </summary>
 public void Exit()
 {
     lock (_lock)
     {
         // Unsubscribe from these symbols
         var symbols = BuildTypeSymbolList(_algorithm);
         if (symbols.Any())
         {
             // don't unsubscribe if there's nothing there, this allows custom data to
             // work with the LiveDataQueue default LEAN implemetation that just throws on every method.
             _dataQueue.Unsubscribe(_job, symbols);
         }
         _exitTriggered = true;
         Bridge.Dispose();
     }
 }
Beispiel #4
0
        /// <summary>
        /// Creates a new instance
        /// </summary>
        public LiveSubscriptionEnumerator(SubscriptionDataConfig dataConfig, IDataQueueHandler dataQueueHandler, EventHandler handler)
        {
            _requestedSymbol      = dataConfig.Symbol;
            _underlyingEnumerator = dataQueueHandler.SubscribeWithMapping(dataConfig, handler, out _currentConfig);

            // for any mapping event we will re subscribe
            dataConfig.NewSymbol += (_, _) =>
            {
                dataQueueHandler.Unsubscribe(_currentConfig);
                _previousEnumerator = _underlyingEnumerator;

                var oldSymbol = _currentConfig.Symbol;
                _underlyingEnumerator = dataQueueHandler.SubscribeWithMapping(dataConfig, handler, out _currentConfig);

                Log.Trace($"LiveSubscriptionEnumerator({_requestedSymbol}): " +
                          $"resubscribing old: '{oldSymbol.Value}' new '{_currentConfig.Symbol.Value}'");
            };
        }
Beispiel #5
0
        /// <summary>
        /// Creates a new instance
        /// </summary>
        public LiveSubscriptionEnumerator(SubscriptionDataConfig dataConfig, IDataQueueHandler dataQueueHandler, EventHandler handler)
        {
            _requestedSymbol = dataConfig.Symbol;
            // we adjust the requested config symbol before sending it to the data queue handler
            _currentConfig        = new SubscriptionDataConfig(dataConfig, symbol: dataConfig.Symbol.GetLiveSubscriptionSymbol());
            _underlyingEnumerator = Subscribe(dataQueueHandler, _currentConfig, handler);

            // for any mapping event we will re subscribe
            dataConfig.NewSymbol += (_, _) =>
            {
                dataQueueHandler.Unsubscribe(_currentConfig);
                _previousEnumerator = _underlyingEnumerator;

                var oldSymbol = _currentConfig.Symbol;
                _currentConfig        = new SubscriptionDataConfig(dataConfig, symbol: dataConfig.Symbol.GetLiveSubscriptionSymbol());
                _underlyingEnumerator = Subscribe(dataQueueHandler, _currentConfig, handler);

                Log.Trace($"LiveSubscriptionEnumerator({_requestedSymbol}): " +
                          $"resubscribing old: '{oldSymbol.Value}' new '{_currentConfig.Symbol.Value}'");
            };
        }
Beispiel #6
0
        /// <summary>
        /// Removes the subscription from the data feed, if it exists
        /// </summary>
        /// <param name="subscription">The subscription to be removed</param>
        /// <returns>True if the subscription was successfully removed, false otherwise</returns>
        public bool RemoveSubscription(Subscription subscription)
        {
            var security = subscription.Security;

            _exchange.RemoveHandler(security.Symbol);

            // request to unsubscribe from the subscription
            if (!security.SubscriptionDataConfig.IsCustomData)
            {
                _dataQueueHandler.Unsubscribe(_job, new Dictionary <SecurityType, List <string> >
                {
                    { security.Type, new List <string> {
                          security.Symbol
                      } }
                });
            }

            // remove the subscription from our collection
            Subscription sub;

            if (_subscriptions.TryRemove(new SymbolSecurityType(security), out sub))
            {
                sub.Dispose();
            }
            else
            {
                return(false);
            }

            Log.Trace("LiveTradingDataFeed.RemoveSubscription(): Removed " + security.Symbol);

            // keep track of security changes, we emit these to the algorithm
            // as notications, used in universe selection
            _changes += SecurityChanges.Removed(security);

            // update our fill forward resolution setting
            _fillForwardResolution.Value = ResolveFillForwardResolution(_algorithm);

            return(true);
        }
 /// <summary>
 /// Clean up
 /// </summary>
 public void Dispose()
 {
     _dataQueueHandler.Unsubscribe(_dataConfig);
     _delistingEnumerator.DisposeSafely();
 }