protected override TimeSpan OnProcess() { var allSecurity = this.GetAllSecurity(); // если фильтр по инструментам выключен (выбран инструмент все инструменты) IEnumerable <HydraTaskSecurity> selectedSecurities = (allSecurity != null ? this.ToHydraSecurities(EntityRegistry.Securities) : Settings.Securities ).ToArray(); var source = new YahooHistorySource(); if (selectedSecurities.IsEmpty()) { this.AddWarningLog(LocalizedStrings.Str2289); source.Refresh(EntityRegistry.Securities, new Security(), SaveSecurity, () => !CanProcess(false)); selectedSecurities = this.ToHydraSecurities(EntityRegistry.Securities); } if (selectedSecurities.IsEmpty()) { this.AddWarningLog(LocalizedStrings.Str2292); return(TimeSpan.MaxValue); } var startDate = _settings.StartFrom; var endDate = DateTime.Today - TimeSpan.FromDays(_settings.DayOffset); var allDates = startDate.Range(endDate, TimeSpan.FromDays(1)).ToArray(); foreach (var security in selectedSecurities) { if (!CanProcess()) { break; } foreach (var series in (allSecurity ?? security).CandleSeries) { if (!CanProcess()) { break; } if (series.CandleType != typeof(TimeFrameCandle)) { this.AddWarningLog(LocalizedStrings.Str2296Params, series); continue; } var storage = StorageRegistry.GetCandleStorage(series.CandleType, security.Security, series.Arg, _settings.Drive, _settings.StorageFormat); var emptyDates = allDates.Except(storage.Dates).ToArray(); if (emptyDates.IsEmpty()) { this.AddInfoLog(LocalizedStrings.Str2297Params, series.Arg, security.Security.Id); continue; } foreach (var emptyDate in emptyDates) { if (!CanProcess()) { break; } if (_settings.IgnoreWeekends && !security.IsTradeDate(emptyDate)) { this.AddDebugLog(LocalizedStrings.WeekEndDate, emptyDate); continue; } try { this.AddInfoLog(LocalizedStrings.Str2298Params, series.Arg, emptyDate, security.Security.Id); var candles = source.GetCandles(security.Security, (TimeSpan)series.Arg, emptyDate, emptyDate + TimeSpan.FromDays(1).Max((TimeSpan)series.Arg)); if (candles.Any()) { SaveCandles(security, candles); } else { this.AddDebugLog(LocalizedStrings.NoData); } } catch (Exception ex) { HandleError(new InvalidOperationException(LocalizedStrings.Str2299Params .Put(series.Arg, emptyDate, security.Security.Id), ex)); } } } } if (CanProcess()) { this.AddInfoLog(LocalizedStrings.Str2300); } return(base.OnProcess()); }
protected override TimeSpan OnProcess() { var allSecurity = this.GetAllSecurity(); // если фильтр по инструментам выключен (выбран инструмент все инструменты) IEnumerable<HydraTaskSecurity> selectedSecurities = (allSecurity != null ? this.ToHydraSecurities(EntityRegistry.Securities) : Settings.Securities ).ToArray(); var source = new YahooHistorySource(); if (selectedSecurities.IsEmpty()) { this.AddWarningLog(LocalizedStrings.Str2289); source.Refresh(EntityRegistry.Securities, new Security(), SaveSecurity, () => !CanProcess(false)); selectedSecurities = this.ToHydraSecurities(EntityRegistry.Securities); } if (selectedSecurities.IsEmpty()) { this.AddWarningLog(LocalizedStrings.Str2292); return TimeSpan.MaxValue; } var startDate = _settings.StartFrom; var endDate = DateTime.Today - TimeSpan.FromDays(_settings.DayOffset); var allDates = startDate.Range(endDate, TimeSpan.FromDays(1)).ToArray(); foreach (var security in selectedSecurities) { if (!CanProcess()) break; foreach (var pair in (allSecurity ?? security).GetCandleSeries()) { if (!CanProcess()) break; if (pair.MessageType != typeof(TimeFrameCandleMessage)) { this.AddWarningLog(LocalizedStrings.Str2296Params, pair); continue; } var tf = (TimeSpan)pair.Arg; var storage = StorageRegistry.GetCandleMessageStorage(pair.MessageType, security.Security, tf, _settings.Drive, _settings.StorageFormat); var emptyDates = allDates.Except(storage.Dates).ToArray(); if (emptyDates.IsEmpty()) { this.AddInfoLog(LocalizedStrings.Str2297Params, tf, security.Security.Id); continue; } var currDate = emptyDates.First(); var lastDate = emptyDates.Last(); while (currDate <= lastDate) { if (!CanProcess()) break; if (_settings.IgnoreWeekends && !security.IsTradeDate(currDate)) { this.AddDebugLog(LocalizedStrings.WeekEndDate, currDate); currDate = currDate.AddDays(1); continue; } try { var till = currDate + TimeSpan.FromDays(_settings.CandleDayStep).Max(tf); this.AddInfoLog(LocalizedStrings.Str2298Params, tf, currDate, till, security.Security.Id); var candles = source.GetCandles(security.Security, tf, currDate, till); if (candles.Any()) SaveCandles(security, candles); else this.AddDebugLog(LocalizedStrings.NoData); } catch (Exception ex) { HandleError(new InvalidOperationException(LocalizedStrings.Str2299Params .Put(tf, currDate, security.Security.Id), ex)); } currDate = currDate.AddDays(_settings.CandleDayStep); } } } if (CanProcess()) this.AddInfoLog(LocalizedStrings.Str2300); return base.OnProcess(); }