/// <summary> /// Initializes a new instance of the <see cref="DataFeedPacket"/> class /// </summary> /// <param name="security">The security whose data is held in this packet</param> /// <param name="configuration">The subscription configuration that produced this data</param> /// <param name="data">The data to add to this packet. The list reference is reused /// internally and NOT copied.</param> /// <param name="isSubscriptionRemoved">Reference to whether or not the subscription has since been removed, defaults to false</param> public DataFeedPacket(ISecurityPrice security, SubscriptionDataConfig configuration, List <BaseData> data, IReadOnlyRef <bool> isSubscriptionRemoved = null) { Security = security; Configuration = configuration; Data = data; _isRemoved = isSubscriptionRemoved ?? Ref.Create(false); }
/// <summary> /// Initializes a new instance of the <see cref="FillForwardEnumerator"/> class that accepts /// a reference to the fill forward resolution, useful if the fill forward resolution is dynamic /// and changing as the enumeration progresses /// </summary> /// <param name="enumerator">The source enumerator to be filled forward</param> /// <param name="exchange">The exchange used to determine when to insert fill forward data</param> /// <param name="fillForwardResolution">The resolution we'd like to receive data on</param> /// <param name="isExtendedMarketHours">True to use the exchange's extended market hours, false to use the regular market hours</param> /// <param name="subscriptionEndTime">The end time of the subscrition, once passing this date the enumerator will stop</param> /// <param name="dataResolution">The source enumerator's data resolution</param> public FillForwardEnumerator(IEnumerator <BaseData> enumerator, SecurityExchange exchange, IReadOnlyRef <TimeSpan> fillForwardResolution, bool isExtendedMarketHours, DateTime subscriptionEndTime, TimeSpan dataResolution ) { _subscriptionEndTime = subscriptionEndTime; Exchange = exchange; _enumerator = enumerator; _dataResolution = dataResolution; _fillForwardResolution = fillForwardResolution; _isExtendedMarketHours = isExtendedMarketHours; }
/// <summary> /// Initializes a new instance of the <see cref="Subscription"/> class with a universe /// </summary> /// <param name="subscriptionRequest">Specified for universe subscriptions</param> /// <param name="enumerator">The subscription's data source</param> /// <param name="timeZoneOffsetProvider">The offset provider used to convert data local times to utc</param> public Subscription( SubscriptionRequest subscriptionRequest, IEnumerator <SubscriptionData> enumerator, TimeZoneOffsetProvider timeZoneOffsetProvider) { _subscriptionRequests = new List <SubscriptionRequest> { subscriptionRequest }; Security = subscriptionRequest.Security; _enumerator = enumerator; IsUniverseSelectionSubscription = subscriptionRequest.IsUniverseSubscription; Configuration = subscriptionRequest.Configuration; OffsetProvider = timeZoneOffsetProvider; UtcStartTime = subscriptionRequest.StartTimeUtc; UtcEndTime = subscriptionRequest.EndTimeUtc; RemovedFromUniverse = Ref.CreateReadOnly(() => _removedFromUniverse); }
/// <summary> /// Initializes a new instance of the <see cref="FillForwardEnumerator"/> class that accepts /// a reference to the fill forward resolution, useful if the fill forward resolution is dynamic /// and changing as the enumeration progresses /// </summary> /// <param name="enumerator">The source enumerator to be filled forward</param> /// <param name="exchange">The exchange used to determine when to insert fill forward data</param> /// <param name="fillForwardResolution">The resolution we'd like to receive data on</param> /// <param name="isExtendedMarketHours">True to use the exchange's extended market hours, false to use the regular market hours</param> /// <param name="subscriptionEndTime">The end time of the subscrition, once passing this date the enumerator will stop</param> /// <param name="dataResolution">The source enumerator's data resolution</param> /// <param name="dataTimeZone">The time zone of the underlying source data. This is used for rounding calculations and /// is NOT the time zone on the BaseData instances (unless of course data time zone equals the exchange time zone)</param> public FillForwardEnumerator(IEnumerator <BaseData> enumerator, SecurityExchange exchange, IReadOnlyRef <TimeSpan> fillForwardResolution, bool isExtendedMarketHours, DateTime subscriptionEndTime, TimeSpan dataResolution, DateTimeZone dataTimeZone ) { _subscriptionEndTime = subscriptionEndTime; Exchange = exchange; _enumerator = enumerator; _dataResolution = dataResolution; _dataTimeZone = dataTimeZone; _fillForwardResolution = fillForwardResolution; _isExtendedMarketHours = isExtendedMarketHours; // '_dataResolution' and '_subscriptionEndTime' are readonly they won't change, so lets calculate this once here since it's expensive _subscriptionEndTimeRoundDownByDataResolution = RoundDown(_subscriptionEndTime, _dataResolution); }
/// <summary> /// Initializes a new instance of the <see cref="Subscription"/> class with a universe /// </summary> /// <param name="universe">Specified for universe subscriptions</param> /// <param name="security">The security this subscription is for</param> /// <param name="configuration">The subscription configuration that was used to generate the enumerator</param> /// <param name="enumerator">The subscription's data source</param> /// <param name="timeZoneOffsetProvider">The offset provider used to convert data local times to utc</param> /// <param name="utcStartTime">The start time of the subscription</param> /// <param name="utcEndTime">The end time of the subscription</param> /// <param name="isUniverseSelectionSubscription">True if this is a subscription for universe selection, /// that is, the configuration is used to produce the used to perform universe selection, false for a /// normal data subscription, i.e, SPY</param> public Subscription(Universe universe, Security security, SubscriptionDataConfig configuration, IEnumerator <SubscriptionData> enumerator, TimeZoneOffsetProvider timeZoneOffsetProvider, DateTime utcStartTime, DateTime utcEndTime, bool isUniverseSelectionSubscription) { Universe = universe; Security = security; _enumerator = enumerator; IsUniverseSelectionSubscription = isUniverseSelectionSubscription; Configuration = configuration; OffsetProvider = timeZoneOffsetProvider; UtcStartTime = utcStartTime; UtcEndTime = utcEndTime; RemovedFromUniverse = Ref.CreateReadOnly(() => _removedFromUniverse); }
/// <summary> /// Initializes a new instance of the <see cref="FillForwardEnumerator"/> class that accepts /// a reference to the fill forward resolution, useful if the fill forward resolution is dynamic /// and changing as the enumeration progresses /// </summary> /// <param name="enumerator">The source enumerator to be filled forward</param> /// <param name="exchange">The exchange used to determine when to insert fill forward data</param> /// <param name="fillForwardResolution">The resolution we'd like to receive data on</param> /// <param name="isExtendedMarketHours">True to use the exchange's extended market hours, false to use the regular market hours</param> /// <param name="subscriptionEndTime">The end time of the subscrition, once passing this date the enumerator will stop</param> /// <param name="dataResolution">The source enumerator's data resolution</param> /// <param name="dataTimeZone">The time zone of the underlying source data. This is used for rounding calculations and /// is NOT the time zone on the BaseData instances (unless of course data time zone equals the exchange time zone)</param> /// <param name="subscriptionStartTime">The subscriptions start time</param> public FillForwardEnumerator(IEnumerator <BaseData> enumerator, SecurityExchange exchange, IReadOnlyRef <TimeSpan> fillForwardResolution, bool isExtendedMarketHours, DateTime subscriptionEndTime, TimeSpan dataResolution, DateTimeZone dataTimeZone, DateTime subscriptionStartTime ) { _subscriptionEndTime = subscriptionEndTime; Exchange = exchange; _enumerator = enumerator; _dataResolution = dataResolution; _dataTimeZone = dataTimeZone; _fillForwardResolution = fillForwardResolution; _isExtendedMarketHours = isExtendedMarketHours; _offsetProvider = new TimeZoneOffsetProvider(Exchange.TimeZone, subscriptionStartTime.ConvertToUtc(Exchange.TimeZone), subscriptionEndTime.ConvertToUtc(Exchange.TimeZone)); }
private Subscription CreateSubscription(Universe universe, IResultHandler resultHandler, Security security, DateTime startTimeUtc, DateTime endTimeUtc, IReadOnlyRef <TimeSpan> fillForwardResolution) { var config = security.SubscriptionDataConfig; var localStartTime = startTimeUtc.ConvertFromUtc(security.Exchange.TimeZone); var localEndTime = endTimeUtc.ConvertFromUtc(security.Exchange.TimeZone); var tradeableDates = Time.EachTradeableDay(security, localStartTime, localEndTime); // ReSharper disable once PossibleMultipleEnumeration if (!tradeableDates.Any()) { _algorithm.Error(string.Format("No data loaded for {0} because there were no tradeable dates for this security.", security.Symbol)); return(null); } // get the map file resolver for this market var mapFileResolver = MapFileResolver.Empty; if (config.SecurityType == SecurityType.Equity) { mapFileResolver = _mapFileProvider.Get(config.Market); } // ReSharper disable once PossibleMultipleEnumeration IEnumerator <BaseData> enumerator = new SubscriptionDataReader(config, localStartTime, localEndTime, resultHandler, mapFileResolver, _factorFileProvider, tradeableDates, false); // optionally apply fill forward logic, but never for tick data if (config.FillDataForward && config.Resolution != Resolution.Tick) { enumerator = new FillForwardEnumerator(enumerator, security.Exchange, fillForwardResolution, security.IsExtendedMarketHours, localEndTime, config.Resolution.ToTimeSpan()); } // finally apply exchange/user filters enumerator = SubscriptionFilterEnumerator.WrapForDataFeed(resultHandler, enumerator, security, localEndTime); var enqueueable = new EnqueueableEnumerator <BaseData>(true); // add this enumerator to our exchange ScheduleEnumerator(enumerator, enqueueable, GetLowerThreshold(config.Resolution), GetUpperThreshold(config.Resolution)); var timeZoneOffsetProvider = new TimeZoneOffsetProvider(security.Exchange.TimeZone, startTimeUtc, endTimeUtc); var subscription = new Subscription(universe, security, enqueueable, timeZoneOffsetProvider, startTimeUtc, endTimeUtc, false); return(subscription); }
/// <summary> /// Initializes a new instance of the <see cref="DataFeedPacket"/> class /// </summary> /// <param name="security">The security whose data is held in this packet</param> /// <param name="configuration">The subscription configuration that produced this data</param> /// <param name="isSubscriptionRemoved">Reference to whether or not the subscription has since been removed, defaults to false</param> public DataFeedPacket(ISecurityPrice security, SubscriptionDataConfig configuration, IReadOnlyRef <bool> isSubscriptionRemoved = null) : this(security, configuration, new List <BaseData>(4), // performance: by default the list has 0 capacity, so lets initialize it with at least 4 (which is the default) isSubscriptionRemoved) { }
/// <summary> /// Initializes a new instance of the <see cref="DataFeedPacket"/> class /// </summary> /// <param name="security">The security whose data is held in this packet</param> /// <param name="configuration">The subscription configuration that produced this data</param> /// <param name="isSubscriptionRemoved">Reference to whether or not the subscription has since been removed, defaults to false</param> public DataFeedPacket(Security security, SubscriptionDataConfig configuration, IReadOnlyRef <bool> isSubscriptionRemoved = null) : this(security, configuration, new List <BaseData>(), isSubscriptionRemoved) { }
/// <summary> /// Initializes a new instance of the <see cref="LiveFillForwardEnumerator"/> class that accepts /// a reference to the fill forward resolution, useful if the fill forward resolution is dynamic /// and changing as the enumeration progresses /// </summary> /// <param name="timeProvider">The source of time used to gauage when this enumerator should emit extra bars when /// null data is returned from the source enumerator</param> /// <param name="enumerator">The source enumerator to be filled forward</param> /// <param name="exchange">The exchange used to determine when to insert fill forward data</param> /// <param name="fillForwardResolution">The resolution we'd like to receive data on</param> /// <param name="isExtendedMarketHours">True to use the exchange's extended market hours, false to use the regular market hours</param> /// <param name="subscriptionEndTime">The end time of the subscrition, once passing this date the enumerator will stop</param> /// <param name="dataResolution">The source enumerator's data resolution</param> public LiveFillForwardEnumerator(ITimeProvider timeProvider, IEnumerator <BaseData> enumerator, SecurityExchange exchange, IReadOnlyRef <TimeSpan> fillForwardResolution, bool isExtendedMarketHours, DateTime subscriptionEndTime, TimeSpan dataResolution) : base(enumerator, exchange, fillForwardResolution, isExtendedMarketHours, subscriptionEndTime, dataResolution) { _timeProvider = timeProvider; }
private Subscription CreateSubscription(Universe universe, IResultHandler resultHandler, Security security, DateTime startTimeUtc, DateTime endTimeUtc, IReadOnlyRef<TimeSpan> fillForwardResolution) { var config = security.SubscriptionDataConfig; var localStartTime = startTimeUtc.ConvertFromUtc(security.Exchange.TimeZone); var localEndTime = endTimeUtc.ConvertFromUtc(security.Exchange.TimeZone); var tradeableDates = Time.EachTradeableDay(security, localStartTime, localEndTime); // ReSharper disable once PossibleMultipleEnumeration if (!tradeableDates.Any()) { _algorithm.Error(string.Format("No data loaded for {0} because there were no tradeable dates for this security.", security.Symbol)); return null; } // get the map file resolver for this market var mapFileResolver = MapFileResolver.Empty; if (config.SecurityType == SecurityType.Equity) mapFileResolver = _mapFileProvider.Get(config.Market); // ReSharper disable once PossibleMultipleEnumeration IEnumerator<BaseData> enumerator = new SubscriptionDataReader(config, localStartTime, localEndTime, resultHandler, mapFileResolver, _factorFileProvider, tradeableDates, false); // optionally apply fill forward logic, but never for tick data if (config.FillDataForward && config.Resolution != Resolution.Tick) { enumerator = new FillForwardEnumerator(enumerator, security.Exchange, fillForwardResolution, security.IsExtendedMarketHours, localEndTime, config.Resolution.ToTimeSpan()); } // finally apply exchange/user filters enumerator = SubscriptionFilterEnumerator.WrapForDataFeed(resultHandler, enumerator, security, localEndTime); var enqueueable = new EnqueueableEnumerator<BaseData>(true); // add this enumerator to our exchange ScheduleEnumerator(enumerator, enqueueable, GetLowerThreshold(config.Resolution), GetUpperThreshold(config.Resolution)); var timeZoneOffsetProvider = new TimeZoneOffsetProvider(security.Exchange.TimeZone, startTimeUtc, endTimeUtc); var subscription = new Subscription(universe, security, enqueueable, timeZoneOffsetProvider, startTimeUtc, endTimeUtc, false); return subscription; }
/// <summary> /// Initializes a new instance of the <see cref="LiveFillForwardEnumerator"/> class that accepts /// a reference to the fill forward resolution, useful if the fill forward resolution is dynamic /// and changing as the enumeration progresses /// </summary> /// <param name="timeProvider">The source of time used to gauage when this enumerator should emit extra bars when /// null data is returned from the source enumerator</param> /// <param name="enumerator">The source enumerator to be filled forward</param> /// <param name="exchange">The exchange used to determine when to insert fill forward data</param> /// <param name="fillForwardResolution">The resolution we'd like to receive data on</param> /// <param name="isExtendedMarketHours">True to use the exchange's extended market hours, false to use the regular market hours</param> /// <param name="subscriptionEndTime">The end time of the subscrition, once passing this date the enumerator will stop</param> /// <param name="dataResolution">The source enumerator's data resolution</param> public LiveFillForwardEnumerator(ITimeProvider timeProvider, IEnumerator<BaseData> enumerator, SecurityExchange exchange, IReadOnlyRef<TimeSpan> fillForwardResolution, bool isExtendedMarketHours, DateTime subscriptionEndTime, TimeSpan dataResolution) : base(enumerator, exchange, fillForwardResolution, isExtendedMarketHours, subscriptionEndTime, dataResolution) { _timeProvider = timeProvider; }