/// <summary>
        /// Gets the default consolidator for the specified symbol and resolution
        /// </summary>
        /// <param name="symbol">The symbo whose data is to be consolidated</param>
        /// <param name="resolution">The resolution for the consolidator, if null, uses the resolution from subscription</param>
        /// <returns>The new default consolidator</returns>
        protected IDataConsolidator ResolveConsolidator(string symbol, Resolution?resolution)
        {
            symbol = symbol.ToUpper();
            try
            {
                // find our subscription to this symbol
                var subscription = SubscriptionManager.Subscriptions.First(x => x.Symbol == symbol);
                if (subscription.Type == typeof(TradeBar))
                {
                    if (!resolution.HasValue)
                    {
                        // if we want the same resolution as in the subscription then just use identity
                        return(new TradeBarConsolidator(1));
                    }

                    return(TradeBarConsolidator.FromResolution(resolution.Value));
                }

                // TODO : Add default IDataConsolidator for Tick
                // if it is tick data we would need a different consolidator, what should the default consolidator of tick data be?
                // I imagine it would be something that produces a TradeBar from ticks!


                // if it is custom data I don't think we can resolve a default consolidator for the type
            }
            catch (InvalidOperationException)
            {
                // this will happen if wedid not find the subscription, let's give the user a decent error message
                throw new Exception("Please register to receive data for symbol '" + symbol + "' using the AddSecurity() function.");
            }

            throw new NotSupportedException("QCAlgorithm.ResolveConsolidator(): Currently this only supports TradeBar data.");
        }
Exemple #2
0
        /// <summary>
        /// Gets the default consolidator for the specified symbol and resolution
        /// </summary>
        /// <param name="symbol">The symbo whose data is to be consolidated</param>
        /// <param name="resolution">The resolution for the consolidator, if null, uses the resolution from subscription</param>
        /// <returns>The new default consolidator</returns>
        protected IDataConsolidator ResolveConsolidator(string symbol, Resolution?resolution)
        {
            symbol = symbol.ToUpper();
            try
            {
                // find our subscription to this symbol
                var subscription = SubscriptionManager.Subscriptions.First(x => x.Symbol == symbol);

                // if the resolution is null or if the requested resolution matches the subscription, return identity
                if (!resolution.HasValue || subscription.Resolution == resolution.Value)
                {
                    // since there's a generic type parameter that we don't have access to, we'll just use the activator
                    var identityConsolidatorType = typeof(IdentityDataConsolidator <>).MakeGenericType(subscription.Type);
                    return((IDataConsolidator)Activator.CreateInstance(identityConsolidatorType));
                }

                // if our type can be used as a trade bar, then let's just make one of those
                // we use IsAssignableFrom instead of IsSubclassOf so that we can account for types that are able to be cast to TradeBar
                if (typeof(TradeBar).IsAssignableFrom(subscription.Type))
                {
                    return(TradeBarConsolidator.FromResolution(resolution.Value));
                }

                // TODO : Add default IDataConsolidator for Tick
                // if it is tick data we would need a different consolidator, what should the default consolidator of tick data be?
                // I imagine it would be something that produces a TradeBar from ticks!


                // if it is custom data I don't think we can resolve a default consolidator for the type unless it was assignable to trade bar
            }
            catch (InvalidOperationException)
            {
                // this will happen if wedid not find the subscription, let's give the user a decent error message
                throw new Exception("Please register to receive data for symbol '" + symbol + "' using the AddSecurity() function.");
            }

            throw new NotSupportedException("QCAlgorithm.ResolveConsolidator(): Currently this only supports TradeBar data.");
        }