/// <summary> /// Checks if the subscription should update the RealTimePrice /// </summary> /// <param name="subscription">The <see cref="Subscription"/></param> /// <param name="timeZoneOffsetProvider">The <see cref="TimeZoneOffsetProvider"/> used to convert now into the timezone of the exchange</param> /// <returns>True if the subscription is not null and the exchange is open</returns> protected bool SubscriptionShouldUpdateRealTimePrice(Subscription subscription, TimeZoneOffsetProvider timeZoneOffsetProvider) { return(subscription != null && subscription.Security.Exchange.Hours.IsOpen( timeZoneOffsetProvider.ConvertFromUtc(_timeProvider.GetUtcNow()), subscription.Security.IsExtendedMarketHours)); }
public void ConvertFromUtcAfterDST() { // the exact instant DST goes into affect var tzDate = new DateTime(2015, 03, 08, 2, 0, 0); var utcDate = tzDate.AddHours(5); var offsetProvider = new TimeZoneOffsetProvider(TimeZones.NewYork, utcDate, utcDate.AddDays(1)); var result = offsetProvider.ConvertFromUtc(utcDate); // We add an hour due to the effect of DST Assert.AreEqual(tzDate + TimeSpan.FromHours(1), result); }
/// <summary> /// Updates the subscription RealTimePrice if the exchange is open /// </summary> /// <param name="subscription">The <see cref="Subscription"/></param> /// <param name="timeZoneOffsetProvider">The <see cref="TimeZoneOffsetProvider"/> used to convert now into the timezone of the exchange</param> /// <param name="exchangeHours">The <see cref="SecurityExchangeHours"/> used to determine /// if the exchange is open and we should update</param> /// <param name="data">The <see cref="BaseData"/> used to update the real time price</param> /// <returns>True if the real time price was updated</returns> protected bool UpdateSubscriptionRealTimePrice( Subscription subscription, TimeZoneOffsetProvider timeZoneOffsetProvider, SecurityExchangeHours exchangeHours, BaseData data) { if (subscription != null && exchangeHours.IsOpen( timeZoneOffsetProvider.ConvertFromUtc(_timeProvider.GetUtcNow()), subscription.Configuration.ExtendedMarketHours)) { subscription.RealtimePrice = data.Value; return(true); } return(false); }