/// <inheritdoc /> public void ScheduleNext() { //need to know in which OvernightMarginJobType we are now and the moment of next change var platformTradingSchedule = _scheduleSettingsCacheService.GetPlatformTradingSchedule(); _overnightMarginParameterContainer.SetOvernightMarginParameterState(false); var currentDateTime = _dateService.Now(); DateTime nextStart; (DateTime Warn, DateTime Start, DateTime End)operatingInterval = default; //no disabled trading schedule items.. doing nothing if (platformTradingSchedule.All(x => x.Enabled()) //OR no disabled intervals in current compilation, schedule recheck || !TryGetOperatingInterval(platformTradingSchedule, currentDateTime, out operatingInterval)) { nextStart = currentDateTime.Date.AddDays(1); } //schedule warning else if (currentDateTime < operatingInterval.Warn) { nextStart = operatingInterval.Warn; } //schedule overnight margin parameter start else if (currentDateTime < operatingInterval.Start) { HandleOvernightMarginWarnings(); nextStart = operatingInterval.Start; } //schedule overnight margin parameter drop else if (currentDateTime < operatingInterval.End) { _overnightMarginParameterContainer.SetOvernightMarginParameterState(true); nextStart = operatingInterval.End; PlanEodJob(operatingInterval.Start, operatingInterval.End, currentDateTime); } else { _log.WriteFatalErrorAsync(nameof(OvernightMarginService), nameof(ScheduleNext), new Exception( $"Incorrect platform trading schedule! Need to fix it and restart the service. Check time: [{currentDateTime:s}], detected operation interval: [{operatingInterval.ToJson()}]")) .Wait(); return; } _log.WriteInfo(nameof(OvernightMarginService), nameof(ScheduleNext), $"Planning next check to [{nextStart:s}]." + $" Current margin parameter state: [{_overnightMarginParameterContainer.GetOvernightMarginParameterState()}]." + $" Check time: [{currentDateTime:s}]." + (operatingInterval != default ? $" Detected operation interval: [{operatingInterval.ToJson()}]." : "")); JobManager.AddJob(ScheduleNext, s => s .WithName(nameof(OvernightMarginService)).NonReentrant().ToRunOnceAt(nextStart)); }
public Task <bool> GetOvernightMarginParameterCurrentState() { return(Task.FromResult(_overnightMarginParameterContainer.GetOvernightMarginParameterState())); }