/// <summary>
 /// Copy constructor with overrides
 /// </summary>
 /// <param name="config">The config to copy, then overrides are applied and all option</param>
 /// <param name="objectType">Type of the data objects.</param>
 /// <param name="symbol">Symbol of the asset we're requesting</param>
 /// <param name="resolution">Resolution of the asset we're requesting</param>
 /// <param name="dataTimeZone">The time zone the raw data is time stamped in</param>
 /// <param name="exchangeTimeZone">Specifies the time zone of the exchange for the security this subscription is for. This
 /// is this output time zone, that is, the time zone that will be used on BaseData instances</param>
 /// <param name="fillForward">Fill in gaps with historical data</param>
 /// <param name="extendedHours">Equities only - send in data from 4am - 8pm</param>
 /// <param name="isInternalFeed">Set to true if this subscription is added for the sole purpose of providing currency conversion rates,
 /// setting this flag to true will prevent the data from being sent into the algorithm's OnData methods</param>
 /// <param name="isCustom">True if this is user supplied custom data, false for normal QC data</param>
 /// <param name="tickType">Specifies if trade or quote data is subscribed</param>
 public SubscriptionDataConfig(SubscriptionDataConfig config,
                               Type objectType               = null,
                               Symbol symbol                 = null,
                               Resolution?resolution         = null,
                               DateTimeZone dataTimeZone     = null,
                               DateTimeZone exchangeTimeZone = null,
                               bool?fillForward              = null,
                               bool?extendedHours            = null,
                               bool?isInternalFeed           = null,
                               bool?isCustom                 = null,
                               TickType?tickType             = null)
     : this(
         objectType ?? config.Type,
         symbol ?? config.Symbol,
         resolution ?? config.Resolution,
         dataTimeZone ?? config.DataTimeZone,
         exchangeTimeZone ?? config.ExchangeTimeZone,
         fillForward ?? config.FillDataForward,
         extendedHours ?? config.ExtendedMarketHours,
         isInternalFeed ?? config.IsInternalFeed,
         isCustom ?? config.IsCustomData,
         tickType ?? config.TickType
         )
 {
 }
Beispiel #2
0
 /// <summary>
 /// Copy constructor with overrides
 /// </summary>
 /// <param name="config">The config to copy, then overrides are applied and all option</param>
 /// <param name="objectType">Type of the data objects.</param>
 /// <param name="symbol">Symbol of the asset we're requesting</param>
 /// <param name="resolution">Resolution of the asset we're requesting</param>
 /// <param name="dataTimeZone">The time zone the raw data is time stamped in</param>
 /// <param name="exchangeTimeZone">Specifies the time zone of the exchange for the security this subscription is for. This
 /// is this output time zone, that is, the time zone that will be used on BaseData instances</param>
 /// <param name="fillForward">Fill in gaps with historical data</param>
 /// <param name="extendedHours">Equities only - send in data from 4am - 8pm</param>
 /// <param name="isInternalFeed">Set to true if this subscription is added for the sole purpose of providing currency conversion rates,
 /// setting this flag to true will prevent the data from being sent into the algorithm's OnData methods</param>
 /// <param name="isCustom">True if this is user supplied custom data, false for normal QC data</param>
 /// <param name="tickType">Specifies if trade or quote data is subscribed</param>
 /// <param name="isFilteredSubscription">True if this subscription should have filters applied to it (market hours/user filters from security), false otherwise</param>
 /// <param name="dataNormalizationMode">Specifies normalization mode used for this subscription</param>
 public SubscriptionDataConfig(SubscriptionDataConfig config,
                               Type objectType               = null,
                               Symbol symbol                 = null,
                               Resolution?resolution         = null,
                               DateTimeZone dataTimeZone     = null,
                               DateTimeZone exchangeTimeZone = null,
                               bool?fillForward              = null,
                               bool?extendedHours            = null,
                               bool?isInternalFeed           = null,
                               bool?isCustom                 = null,
                               TickType?tickType             = null,
                               bool?isFilteredSubscription   = null,
                               DataNormalizationMode?dataNormalizationMode = null)
     : this(
         objectType ?? config.Type,
         symbol ?? config.Symbol,
         resolution ?? config.Resolution,
         dataTimeZone ?? config.DataTimeZone,
         exchangeTimeZone ?? config.ExchangeTimeZone,
         fillForward ?? config.FillDataForward,
         extendedHours ?? config.ExtendedMarketHours,
         isInternalFeed ?? config.IsInternalFeed,
         isCustom ?? config.IsCustomData,
         tickType ?? config.TickType,
         isFilteredSubscription ?? config.IsFilteredSubscription,
         dataNormalizationMode ?? config.DataNormalizationMode
         )
 {
     PriceScaleFactor = config.PriceScaleFactor;
     SumOfDividends   = config.SumOfDividends;
     Consolidators    = config.Consolidators;
 }
Beispiel #3
0
        public void ValidatesSubscriptionTickTypesForConsolidators(
            SecurityType securityType,
            Resolution subscriptionResolution,
            Type subscriptionDataType,
            TickType?subscriptionTickType,
            Type consolidatorOutputType,
            bool expected)
        {
            var subscription = new SubscriptionDataConfig(
                subscriptionDataType,
                Symbol.Create("XYZ", securityType, QuantConnect.Market.USA),
                subscriptionResolution,
                DateTimeZone.Utc,
                DateTimeZone.Utc,
                true,
                false,
                false,
                false,
                subscriptionTickType);

            var consolidator = new TestConsolidator(subscriptionDataType, consolidatorOutputType);

            Assert.AreEqual(expected, SubscriptionManager.IsSubscriptionValidForConsolidator(subscription, consolidator));
        }
Beispiel #4
0
        /// <summary>
        /// Creates the zip file name for a QC zip data file
        /// </summary>
        public static string GenerateZipFileName(string symbol, SecurityType securityType, DateTime date, Resolution resolution, TickType?tickType = null)
        {
            if (resolution == Resolution.Hour || resolution == Resolution.Daily)
            {
                return($"{symbol.ToLowerInvariant()}.zip");
            }

            var zipFileName = date.ToStringInvariant(DateFormat.EightCharacter);

            if (tickType == null)
            {
                if (securityType == SecurityType.Forex || securityType == SecurityType.Cfd)
                {
                    tickType = TickType.Quote;
                }
                else
                {
                    tickType = TickType.Trade;
                }
            }

            var suffix = Invariant($"_{tickType.Value.TickTypeToLower()}.zip");

            return(zipFileName + suffix);
        }
Beispiel #5
0
        /// <summary>
        /// Constructor for Data Subscriptions
        /// </summary>
        /// <param name="objectType">Type of the data objects.</param>
        /// <param name="symbol">Symbol of the asset we're requesting</param>
        /// <param name="resolution">Resolution of the asset we're requesting</param>
        /// <param name="dataTimeZone">The time zone the raw data is time stamped in</param>
        /// <param name="exchangeTimeZone">Specifies the time zone of the exchange for the security this subscription is for. This
        /// is this output time zone, that is, the time zone that will be used on BaseData instances</param>
        /// <param name="fillForward">Fill in gaps with historical data</param>
        /// <param name="extendedHours">Equities only - send in data from 4am - 8pm</param>
        /// <param name="isInternalFeed">Set to true if this subscription is added for the sole purpose of providing currency conversion rates,
        /// setting this flag to true will prevent the data from being sent into the algorithm's OnData methods</param>
        /// <param name="isCustom">True if this is user supplied custom data, false for normal QC data</param>
        /// <param name="tickType">Specifies if trade or quote data is subscribed</param>
        /// <param name="isFilteredSubscription">True if this subscription should have filters applied to it (market hours/user filters from security), false otherwise</param>
        /// <param name="dataNormalizationMode">Specifies normalization mode used for this subscription</param>
        public SubscriptionDataConfig(Type objectType,
                                      Symbol symbol,
                                      Resolution resolution,
                                      DateTimeZone dataTimeZone,
                                      DateTimeZone exchangeTimeZone,
                                      bool fillForward,
                                      bool extendedHours,
                                      bool isInternalFeed,
                                      bool isCustom               = false,
                                      TickType?tickType           = null,
                                      bool isFilteredSubscription = true,
                                      DataNormalizationMode dataNormalizationMode = DataNormalizationMode.Adjusted)
        {
            if (objectType == null)
            {
                throw new ArgumentNullException("objectType");
            }
            if (symbol == null)
            {
                throw new ArgumentNullException("symbol");
            }
            if (dataTimeZone == null)
            {
                throw new ArgumentNullException("dataTimeZone");
            }
            if (exchangeTimeZone == null)
            {
                throw new ArgumentNullException("exchangeTimeZone");
            }

            Type                   = objectType;
            SecurityType           = symbol.ID.SecurityType;
            Resolution             = resolution;
            _sid                   = symbol.ID;
            Symbol                 = symbol;
            FillDataForward        = fillForward;
            ExtendedMarketHours    = extendedHours;
            PriceScaleFactor       = 1;
            IsInternalFeed         = isInternalFeed;
            IsCustomData           = isCustom;
            Market                 = symbol.ID.Market;
            DataTimeZone           = dataTimeZone;
            ExchangeTimeZone       = exchangeTimeZone;
            IsFilteredSubscription = isFilteredSubscription;
            Consolidators          = new HashSet <IDataConsolidator>();
            DataNormalizationMode  = dataNormalizationMode;

            TickType = tickType ?? LeanData.GetCommonTickTypeForCommonDataTypes(objectType, SecurityType);

            switch (resolution)
            {
            case Resolution.Tick:
                //Ticks are individual sales and fillforward doesn't apply.
                Increment       = TimeSpan.FromSeconds(0);
                FillDataForward = false;
                break;

            case Resolution.Second:
                Increment = TimeSpan.FromSeconds(1);
                break;

            case Resolution.Minute:
                Increment = TimeSpan.FromMinutes(1);
                break;

            case Resolution.Hour:
                Increment = TimeSpan.FromHours(1);
                break;

            case Resolution.Daily:
                Increment = TimeSpan.FromDays(1);
                break;

            default:
                throw new InvalidEnumArgumentException("Unexpected Resolution: " + resolution);
            }
        }
        /// <summary>
        /// Constructor for Data Subscriptions
        /// </summary>
        /// <param name="objectType">Type of the data objects.</param>
        /// <param name="symbol">Symbol of the asset we're requesting</param>
        /// <param name="resolution">Resolution of the asset we're requesting</param>
        /// <param name="dataTimeZone">The time zone the raw data is time stamped in</param>
        /// <param name="exchangeTimeZone">Specifies the time zone of the exchange for the security this subscription is for. This
        /// is this output time zone, that is, the time zone that will be used on BaseData instances</param>
        /// <param name="fillForward">Fill in gaps with historical data</param>
        /// <param name="extendedHours">Equities only - send in data from 4am - 8pm</param>
        /// <param name="isInternalFeed">Set to true if this subscription is added for the sole purpose of providing currency conversion rates,
        /// setting this flag to true will prevent the data from being sent into the algorithm's OnData methods</param>
        /// <param name="isCustom">True if this is user supplied custom data, false for normal QC data</param>
        /// <param name="tickType">Specifies if trade or quote data is subscribed</param>
        public SubscriptionDataConfig(Type objectType,
                                      Symbol symbol,
                                      Resolution resolution,
                                      DateTimeZone dataTimeZone,
                                      DateTimeZone exchangeTimeZone,
                                      bool fillForward,
                                      bool extendedHours,
                                      bool isInternalFeed,
                                      bool isCustom     = false,
                                      TickType?tickType = null)
        {
            Type                = objectType;
            SecurityType        = symbol.ID.SecurityType;
            Resolution          = resolution;
            _sid                = symbol.ID;
            FillDataForward     = fillForward;
            ExtendedMarketHours = extendedHours;
            PriceScaleFactor    = 1;
            MappedSymbol        = symbol.Value;
            IsInternalFeed      = isInternalFeed;
            IsCustomData        = isCustom;
            Market              = symbol.ID.Market;
            DataTimeZone        = dataTimeZone;
            ExchangeTimeZone    = exchangeTimeZone;
            Consolidators       = new HashSet <IDataConsolidator>();

            if (!tickType.HasValue)
            {
                TickType = TickType.Trade;
                if (SecurityType == SecurityType.Forex || SecurityType == SecurityType.Cfd)
                {
                    TickType = TickType.Quote;
                }
            }
            else
            {
                TickType = tickType.Value;
            }

            switch (resolution)
            {
            case Resolution.Tick:
                //Ticks are individual sales and fillforward doesn't apply.
                Increment       = TimeSpan.FromSeconds(0);
                FillDataForward = false;
                break;

            case Resolution.Second:
                Increment = TimeSpan.FromSeconds(1);
                break;

            case Resolution.Minute:
                Increment = TimeSpan.FromMinutes(1);
                break;

            case Resolution.Hour:
                Increment = TimeSpan.FromHours(1);
                break;

            case Resolution.Daily:
                Increment = TimeSpan.FromDays(1);
                break;

            default:
                throw new InvalidEnumArgumentException("Unexpected Resolution: " + resolution);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Creates the zip file name for a QC zip data file
        /// </summary>
        public static string GenerateZipFileName(string symbol, SecurityType securityType, DateTime date, Resolution resolution, TickType?tickType = null)
        {
            if (resolution == Resolution.Hour || resolution == Resolution.Daily)
            {
                return(symbol.ToLower() + ".zip");
            }

            var zipFileName = date.ToString(DateFormat.EightCharacter);

            tickType = tickType ?? (securityType == SecurityType.Forex || securityType == SecurityType.Cfd ? TickType.Quote : TickType.Trade);
            var suffix = string.Format("_{0}.zip", tickType.Value.ToLower());

            return(zipFileName + suffix);
        }
 /// <summary>
 /// Initialize model class for passing in parameters for historical data
 /// </summary>
 /// <param name="symbol">Symbol for the data we're looking for.</param>
 /// <param name="resolution">Resolution of the data request</param>
 /// <param name="startUtc">Start time of the data in UTC</param>
 /// <param name="endUtc">End time of the data in UTC</param>
 /// <param name="tickType">[Optional] The type of tick to get. Defaults to <see cref="QuantConnect.TickType.Trade"/></param>
 public DataDownloaderGetParameters(Symbol symbol, Resolution resolution, DateTime startUtc, DateTime endUtc, TickType?tickType = null)
 {
     Symbol     = symbol;
     Resolution = resolution;
     StartUtc   = startUtc;
     EndUtc     = endUtc;
     TickType   = tickType ?? TickType.Trade;
 }
Beispiel #9
0
 private SubscriptionDataConfig GetSubscriptionDataConfig(Type T, Symbol symbol, Resolution resolution, TickType?tickType = null)
 {
     return(new SubscriptionDataConfig(
                T,
                symbol,
                resolution,
                TimeZones.Utc,
                TimeZones.Utc,
                true,
                true,
                false,
                tickType: tickType));
 }
 private SubscriptionDataConfig GetSubscriptionDataConfig <T>(Symbol symbol, Resolution resolution, TickType?tickType = null)
 {
     return(GetSubscriptionDataConfig(typeof(T), symbol, resolution, tickType));
 }