Ejemplo n.º 1
0
 /// <summary>
 /// Schedules the callback to run using the specified date and time rules
 /// </summary>
 /// <param name="name">The event's unique name</param>
 /// <param name="dateRule">Specifies what dates the event should run</param>
 /// <param name="timeRule">Specifies the times on those dates the event should run</param>
 /// <param name="callback">The callback to be invoked</param>
 public void On(string name, IDateRule dateRule, ITimeRule timeRule, Action callback)
 {
     var dates = dateRule.GetDates(_securities.UtcTime, Time.EndOfTime);
     var eventTimes = timeRule.CreateUtcEventTimes(dates);
     var scheduledEvent = new ScheduledEvent(name, eventTimes, (s, time) => callback());
     _eventSchedule.Add(scheduledEvent);
 }
        /// <summary>
        /// Schedules the callback to run using the specified date and time rules
        /// </summary>
        /// <param name="name">The event's unique name</param>
        /// <param name="dateRule">Specifies what dates the event should run</param>
        /// <param name="timeRule">Specifies the times on those dates the event should run</param>
        /// <param name="callback">The callback to be invoked</param>
        public ScheduledEvent On(string name, IDateRule dateRule, ITimeRule timeRule, Action <string, DateTime> callback)
        {
            // back the date up to ensure we get all events, the event scheduler will skip past events that whose time has passed
            var dates          = dateRule.GetDates(_securities.UtcTime.Date.AddDays(-1), Time.EndOfTime);
            var eventTimes     = timeRule.CreateUtcEventTimes(dates);
            var scheduledEvent = new ScheduledEvent(name, eventTimes, callback);

            Add(scheduledEvent);

            var exampleTimes = eventTimes.Take(3)
                               .Select(x => x.ToString())
                               .ToArray();

            if (exampleTimes.Length > 0)
            {
                Log.Trace("Event Name \"{0}\", scheduled to run at {1} (UTC){2}",
                          name, string.Join(", ", exampleTimes),
                          exampleTimes.Length > 1? "..." : "");
            }
            else
            {
                Log.Trace("Event Name \"{0}\", scheduled to run, but no event times were selected", name);
            }

            return(scheduledEvent);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get an enumerator of UTC DateTimes that defines when this universe will be invoked
        /// </summary>
        /// <param name="startTimeUtc">The start time of the range in UTC</param>
        /// <param name="endTimeUtc">The end time of the range in UTC</param>
        /// <returns>An enumerator of UTC DateTimes that defines when this universe will be invoked</returns>
        public IEnumerable <DateTime> GetTriggerTimes(DateTime startTimeUtc, DateTime endTimeUtc, MarketHoursDatabase marketHoursDatabase)
        {
            var startTimeLocal = startTimeUtc.ConvertFromUtc(Configuration.ExchangeTimeZone);
            var endTimeLocal   = endTimeUtc.ConvertFromUtc(Configuration.ExchangeTimeZone);

            // define date/time rule enumerable
            var dates = _dateRule.GetDates(startTimeLocal, endTimeLocal);
            var times = _timeRule.CreateUtcEventTimes(dates).GetEnumerator();

            // Make sure and filter out any times before our start time
            // GH #5440
            do
            {
                if (!times.MoveNext())
                {
                    times.Dispose();
                    yield break;
                }
            }while (times.Current < startTimeUtc);

            // Start yielding times
            do
            {
                yield return(times.Current);
            }while (times.MoveNext());
            times.Dispose();
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Helper methods to defer the evaluation of the current time until the dates are enumerated for the first time.
 /// This allows for correct support for warmup period
 /// </summary>
 internal static IEnumerable <DateTime> GetDatesDeferred(IDateRule dateRule, SecurityManager securities)
 {
     foreach (var item in dateRule.GetDates(securities.UtcTime.Date.AddDays(-1), Time.EndOfTime))
     {
         yield return(item);
     }
 }
Ejemplo n.º 5
0
        public ScheduledEvent On(string name, IDateRule dateRule, ITimeRule timeRule, Action <string, DateTime> callback)
        {
            var dates          = dateRule.GetDates(_securities.UtcTime.Date.AddDays(-1), Time.EndOfTime);
            var eventTimes     = timeRule.CreateUtcEventTimes(dates);
            var scheduledEvent = new ScheduledEvent(name, eventTimes, callback);

            Add(scheduledEvent);
            return(scheduledEvent);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Schedules the callback to run using the specified date and time rules
        /// </summary>
        /// <param name="name">The event's unique name</param>
        /// <param name="dateRule">Specifies what dates the event should run</param>
        /// <param name="timeRule">Specifies the times on those dates the event should run</param>
        /// <param name="callback">The callback to be invoked</param>
        public ScheduledEvent On(string name, IDateRule dateRule, ITimeRule timeRule, Action <string, DateTime> callback)
        {
            // back the date up to ensure we get all events, the event scheduler will skip past events that whose time has passed
            var dates          = dateRule.GetDates(_securities.UtcTime.Date.AddDays(-1), Time.EndOfTime);
            var eventTimes     = timeRule.CreateUtcEventTimes(dates);
            var scheduledEvent = new ScheduledEvent(name, eventTimes, callback);

            Add(scheduledEvent);
            return(scheduledEvent);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns an enumerator that defines when this user defined universe will be invoked
        /// </summary>
        /// <returns>An enumerator of DateTime that defines when this universe will be invoked</returns>
        public IEnumerable <DateTime> GetTriggerTimes(DateTime startTimeUtc, DateTime endTimeUtc, MarketHoursDatabase marketHoursDatabase)
        {
            var startTimeLocal = startTimeUtc.ConvertFromUtc(Configuration.ExchangeTimeZone);
            var endTimeLocal   = endTimeUtc.ConvertFromUtc(Configuration.ExchangeTimeZone);

            // define date/time rule enumerable
            var dates = _dateRule.GetDates(startTimeLocal, endTimeLocal);

            foreach (var time in _timeRule.CreateUtcEventTimes(dates))
            {
                yield return(time);
            }
        }
Ejemplo n.º 8
0
        ScheduledEvent IFluentSchedulingRunnable.Run(Action <string, DateTime> callback)
        {
            var name       = _name ?? _dateRule.Name + ": " + _timeRule.Name;
            var dates      = _dateRule.GetDates(_securities.UtcTime.Date.AddDays(-1), Time.EndOfTime);
            var eventTimes = _timeRule.CreateUtcEventTimes(dates);

            if (_predicate != null)
            {
                eventTimes = eventTimes.Where(_predicate);
            }
            var scheduledEvent = new ScheduledEvent(name, eventTimes, callback);

            _schedule.Add(scheduledEvent);
            return(scheduledEvent);
        }
        /// <summary>
        /// Register the defined event with the callback
        /// </summary>
        ScheduledEvent IFluentSchedulingRunnable.Run(Action <string, DateTime> callback)
        {
            var name = _name ?? _dateRule.Name + ": " + _timeRule.Name;
            // back the date up to ensure we get all events, the event scheduler will skip past events that whose time has passed
            var dates      = _dateRule.GetDates(_securities.UtcTime.Date.AddDays(-1), Time.EndOfTime);
            var eventTimes = _timeRule.CreateUtcEventTimes(dates);

            if (_predicate != null)
            {
                eventTimes = eventTimes.Where(_predicate);
            }
            var scheduledEvent = new ScheduledEvent(name, eventTimes, callback);

            _schedule.Add(scheduledEvent);
            return(scheduledEvent);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Schedules the callback to run using the specified date and time rules
        /// </summary>
        /// <param name="name">The event's unique name</param>
        /// <param name="dateRule">Specifies what dates the event should run</param>
        /// <param name="timeRule">Specifies the times on those dates the event should run</param>
        /// <param name="callback">The callback to be invoked</param>
        public ScheduledEvent On(string name, IDateRule dateRule, ITimeRule timeRule, Action <string, DateTime> callback)
        {
            // back the date up to ensure we get all events, the event scheduler will skip past events that whose time has passed
            var dates          = dateRule.GetDates(_securities.UtcTime.Date.AddDays(-1), Time.EndOfTime);
            var eventTimes     = timeRule.CreateUtcEventTimes(dates);
            var scheduledEvent = new ScheduledEvent(name, eventTimes, callback);

            Add(scheduledEvent);

            // ScheduledEvent constructor will prime the scheduled event
            if (scheduledEvent.NextEventUtcTime != DateTime.MaxValue)
            {
                Log.Trace($"Event Name \"{scheduledEvent.Name}\", scheduled to run at {scheduledEvent.NextEventUtcTime} (UTC)...");
            }
            else
            {
                Log.Error($"Event Name \"{scheduledEvent.Name}\", scheduled to run, but no event times were selected");
            }

            return(scheduledEvent);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Schedules the callback to run using the specified date and time rules
 /// </summary>
 /// <param name="name">The event's unique name</param>
 /// <param name="dateRule">Specifies what dates the event should run</param>
 /// <param name="timeRule">Specifies the times on those dates the event should run</param>
 /// <param name="callback">The callback to be invoked</param>
 public ScheduledEvent On(string name, IDateRule dateRule, ITimeRule timeRule, Action<string, DateTime> callback)
 {
     // back the date up to ensure we get all events, the event scheduler will skip past events that whose time has passed
     var dates = dateRule.GetDates(_securities.UtcTime.Date.AddDays(-1), Time.EndOfTime);
     var eventTimes = timeRule.CreateUtcEventTimes(dates);
     var scheduledEvent = new ScheduledEvent(name, eventTimes, callback);
     Add(scheduledEvent);
     return scheduledEvent;
 }