Exemple #1
0
        /// <summary>
        /// Gets existing or adds new <see cref="SubscriptionDataConfig" />
        /// </summary>
        /// <returns>Returns the SubscriptionDataConfig instance used</returns>
        public SubscriptionDataConfig SubscriptionManagerGetOrAdd(SubscriptionDataConfig newConfig)
        {
            var config = _subscriptionManagerSubscriptions.GetOrAdd(newConfig, newConfig);

            // if the reference is not the same, means it was already there and we did not add anything new
            if (!ReferenceEquals(config, newConfig))
            {
                Log.Debug("DataManager.SubscriptionManagerGetOrAdd(): subscription already added: " + config);
            }
            else
            {
                // count data subscriptions by symbol, ignoring multiple data types
                var uniqueCount = SubscriptionManagerSubscriptions
                                  .Where(x => !x.Symbol.IsCanonical())
                                  // TODO should limit subscriptions or unique securities
                                  .DistinctBy(x => x.Symbol.Value)
                                  .Count();

                if (uniqueCount > _algorithmSettings.DataSubscriptionLimit)
                {
                    throw new Exception(
                              $"The maximum number of concurrent market data subscriptions was exceeded ({_algorithmSettings.DataSubscriptionLimit})." +
                              "Please reduce the number of symbols requested or increase the limit using Settings.DataSubscriptionLimit.");
                }

                // add the time zone to our time keeper
                _timeKeeper.AddTimeZone(newConfig.ExchangeTimeZone);

                // if is custom data, sets HasCustomData to true
                HasCustomData = HasCustomData || newConfig.IsCustomData;
            }

            return(config);
        }
Exemple #2
0
        /// <summary>
        /// Gets existing or adds new <see cref="SubscriptionDataConfig" />
        /// </summary>
        /// <returns>Returns the SubscriptionDataConfig instance used</returns>
        public SubscriptionDataConfig SubscriptionManagerGetOrAdd(SubscriptionDataConfig newConfig)
        {
            var config = _subscriptionManagerSubscriptions.GetOrAdd(newConfig, newConfig);

            // if the reference is not the same, means it was already there and we did not add anything new
            if (!ReferenceEquals(config, newConfig))
            {
                // 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
                if (Log.DebuggingEnabled)
                {
                    Log.Debug("DataManager.SubscriptionManagerGetOrAdd(): subscription already added: " + config);
                }
            }
            else
            {
                // for performance, only count if we are above the limit
                if (SubscriptionManagerCount() > _algorithmSettings.DataSubscriptionLimit)
                {
                    // count data subscriptions by symbol, ignoring multiple data types.
                    // this limit was added due to the limits IB places on number of subscriptions
                    var uniqueCount = SubscriptionManagerSubscriptions
                                      .Where(x => !x.Symbol.IsCanonical())
                                      .DistinctBy(x => x.Symbol.Value)
                                      .Count();

                    if (uniqueCount > _algorithmSettings.DataSubscriptionLimit)
                    {
                        throw new Exception(
                                  $"The maximum number of concurrent market data subscriptions was exceeded ({_algorithmSettings.DataSubscriptionLimit})." +
                                  "Please reduce the number of symbols requested or increase the limit using Settings.DataSubscriptionLimit.");
                    }
                }

                // add the time zone to our time keeper
                _timeKeeper.AddTimeZone(newConfig.ExchangeTimeZone);

                // if is custom data, sets HasCustomData to true
                HasCustomData = HasCustomData || newConfig.IsCustomData;
            }

            return(config);
        }