private static bool TryMoveNext(LiveSubscription subscription, out BaseData data) { data = null; if (subscription.NeedsMoveNext) { // if we didn't emit the previous value it's because it was in // the future, so don't call MoveNext, just perform the date range // checks below again // in live mode subscription reader will move next but return null for current since nothing is there if (!subscription.MoveNext()) { // we've exhaused this source for now, the only source that would do this is // a remote file, let's wait for five minutes and check again to see if we can // get another piece of data. sadly, in this case it does mean redownloading the // entire file and reading through all the data before getting to the end to see // if there's a new line subscription.SetNextUpdateTime(TimeSpan.FromMinutes(5)); return(false); } // true success defined as if we got a non-null value if (subscription.Current == null) { Log.Trace("LiveTradingDataFeed.Custom(): Current == null"); return(false); } } // if we didn't get anything keep going data = subscription.Current; if (data == null) { // heuristically speaking this should already be true, but no harm in explicitly setting it subscription.NeedsMoveNext = true; return(false); } return(true); }
/// <summary> /// Adds a new subscription for universe selection /// </summary> /// <param name="universe">The universe to add a subscription for</param> /// <param name="startTimeUtc">The start time of the subscription in utc</param> /// <param name="endTimeUtc">The end time of the subscription in utc</param> public void AddUniverseSubscription( IUniverse universe, DateTime startTimeUtc, DateTime endTimeUtc ) { // grab the relevant exchange hours SubscriptionDataConfig config = universe.Configuration; var exchangeHours = SecurityExchangeHoursProvider.FromDataFolder() .GetExchangeHours(config.Market, null, config.SecurityType); // create a canonical security object var security = new Security(exchangeHours, config, universe.SubscriptionSettings.Leverage); var localStartTime = startTimeUtc.ConvertFromUtc(config.TimeZone); var localEndTime = endTimeUtc.ConvertFromUtc(config.TimeZone); // define our data enumerator var tradeableDates = Time.EachTradeableDay(security, localStartTime, localEndTime); var enumerator = new SubscriptionDataReader(config, localStartTime, localEndTime, _resultHandler, tradeableDates, false); // create the subscription var subscription = new LiveSubscription(universe, security, enumerator, startTimeUtc, endTimeUtc); // only message the user if it's one of their universe types _subscriptions.AddOrUpdate(new SymbolSecurityType(subscription), subscription); }
private static bool TryMoveNext(LiveSubscription subscription, out BaseData data) { data = null; if (subscription.NeedsMoveNext) { // if we didn't emit the previous value it's because it was in // the future, so don't call MoveNext, just perform the date range // checks below again // in live mode subscription reader will move next but return null for current since nothing is there if (!subscription.MoveNext()) { // we've exhaused this source for now, the only source that would do this is // a remote file, let's wait for five minutes and check again to see if we can // get another piece of data. sadly, in this case it does mean redownloading the // entire file and reading through all the data before getting to the end to see // if there's a new line subscription.SetNextUpdateTime(TimeSpan.FromMinutes(5)); return false; } // true success defined as if we got a non-null value if (subscription.Current == null) { Log.Trace("LiveTradingDataFeed.Custom(): Current == null"); return false; } } // if we didn't get anything keep going data = subscription.Current; if (data == null) { // heuristically speaking this should already be true, but no harm in explicitly setting it subscription.NeedsMoveNext = true; return false; } return true; }
private static bool TryMoveNext(LiveSubscription subscription, out BaseData data) { data = null; if (subscription.NeedsMoveNext) { // if we didn't emit the previous value it's because it was in // the future, so don't call MoveNext, just perform the date range // checks below again // in live mode subscription reader will move next but return null for current since nothing is there subscription.MoveNext(); // true success defined as if we got a non-null value if (subscription.Current == null) { Log.Trace("LiveTradingDataFeed.Custom(): Current == null"); return false; } } // if we didn't get anything keep going data = subscription.Current; if (data == null) { // heuristically speaking this should already be true, but no harm in explicitly setting it subscription.NeedsMoveNext = true; return false; } return true; }