• Version 1.15.2
Show / Hide Table of Contents

Session Schedule

The SessionSchedule class allows specifying time intervals when a session must be logged on (active). It also allows to automatically reset message sequence numbers.

Parameters

The SessionSchedule constructor creates the session schedule.

The first two parameters ( firstDay and lastDay ) define a working week. During these days, the session will always be connected at the logon time and disconnected at the logout time if the session duration equals to a single day. If the session must be active for the entire week, then the scheduler will connect the session at the logon time on the day that is specified by the firstDay parameter and disconnect it at the logout time on the day specified by the lastDay parameter.

Note

It is possible for the firstDay parameter value to be greater than the value of the lastDay parameter. In this case, the schedule will cross the end of the week and continue until the lastDay.

If the firstDay and lastDay parameters have the same value, then the length (number of days) of the working week depends on the values of the logonTime and the logoutTime parameters:

  • If the logonTime is less than the logoutTime, then the working week will be a single day.
  • If the logonTime is greater than the logoutTime, then the working week will be seven days (the first logon will be performed at the logon time on the first day, the last logout will be performed at the logout time a week later).

The logonTime and logoutTime parameters define the logon and logout time for the session for each working day if the session duration is a single day. If the session must continue for the entire week, then the logonTime parameter value specifies the time for the logon to be performed on the first day of the working week, and the logoutTime parameter value specifies the time of the logout to be performed on the last day of the working week.

The sessionDuration parameter defines whether the session must continue for the entire working week (see Week), or the working time is limited to a single day (see Day).

Note

If the session duration is equal to Day and the value of the logoutTime parameter is less than the logonTime parameter value, then it is assumed that the working time crosses midnight. In this case, the session scheduler will disconnect the session the next day.

The seqNumberResetPolicy parameter specifies whether message sequence numbers must be reset and on which basis (daily or weekly).

Note

The value of the seqNumberResetPolicy parameter must match the value of the sessionDuration parameter. For example, message sequence numbers cannot be reset on a daily basis if the logon/logout frequency is once per week.

For example:

// Session is active from 8:00 until 17:00 each working day.
var regularSingleDay = new SessionSchedule(DayOfWeek.Monday, DayOfWeek.Friday, new TimeSpan(8, 0, 0), new TimeSpan(17, 0, 0), SessionDuration.Day, SequenceNumberResetPolicy.Never);

// Session starts on Monday at 8:00 and continues until 17:00 on Friday
var regularWeek = new SessionSchedule(DayOfWeek.Monday, DayOfWeek.Friday, new TimeSpan(8, 0, 0), new TimeSpan(17, 0, 0), SessionDuration.Week, SequenceNumberResetPolicy.Never);

// Session starts on Monday at 23:00, crosses midnight and is disconnected at 05:00 on Tuesday.
// The next FIX connection is established on Tuesday at 23:00 and finished at 05:00 on Wednesday.
// And so on..
// The last logon will be performed on Friday, at 23:00 and the final logout will occur at 5:00 on Saturday morning.
// Next Monday, before the logon, message sequence numbers will be reset.
var crossMidnightSingleDay = new SessionSchedule(DayOfWeek.Monday, DayOfWeek.Saturday, new TimeSpan(23, 0, 0), new TimeSpan(5, 0, 0), SessionDuration.Day, SequenceNumberResetPolicy.Weekly);

// Session starts on Friday at 16:00, continues four calendar days and is disconnected on Monday, at 02:00.
var crossMidnightWeek = new SessionSchedule(DayOfWeek.Friday, DayOfWeek.Monday, new TimeSpan(16, 0, 0), new TimeSpan(2, 0, 0), SessionDuration.Week, SequenceNumberResetPolicy.Never);

Time Zone

By default, the Scheduler uses the local time to determine when a session should be connected/disconnected.

Use the UtcTimeUsage property for switching to UTC.

Advanced Cases

The SessionSchedule constructor supports common use cases.

However, sometimes it is necessary to set different logon and logout times for different days. The scheduler provides this ability via the LogonTimes and LogoutTimes properties.

These properties return a collection of TimeSpan values for the logon or logout event for each day in the week starting from Sunday till Saturday. Modifying entries of these collections gives the ability to define different logon/logout time for different days.

Different Logon / Logout Times

The following example demonstrates how a schedule can be updated to disconnect the session on Friday earlier.

// Construct the schedule with the same logon/logout time for all days.
var shortFriday = new SessionSchedule(DayOfWeek.Monday, DayOfWeek.Friday, new TimeSpan(8, 0, 0), new TimeSpan(17, 0, 0), SessionDuration.Day, SequenceNumberResetPolicy.Never);
// Update the logout time for Friday.
shortFriday.LogoutTimes[(int)DayOfWeek.Friday] = new TimeSpan(16, 30, 0);

Day Off

Another example demonstrates how the schedule can be updated to define one day off in the middle of the working week.

// Construct the schedule with the same logon/logout time for all days.
var dayOffOnWednesday = new SessionSchedule(DayOfWeek.Monday, DayOfWeek.Friday, new TimeSpan(8, 0, 0), new TimeSpan(17, 0, 0), SessionDuration.Day, SequenceNumberResetPolicy.Never);

// Disable logon and logout on Wednesday.
dayOffOnWednesday.LogonTimes[(int)DayOfWeek.Wednesday] = dayOffOnWednesday.LogoutTimes[(int)DayOfWeek.Wednesday] = TimeSpan.MinValue;

Multiple Schedules

Sometimes it is necessary to pause during a working day and continue the work after a break. To support this use case, the scheduler can register multiple schedules for the session.

The example below demonstrates how to use multiple schedules to achieve the following behavior each working day:

  • Logon at 8:00 (do sequence numbers reset) - Logout at 12:00
  • Logon at 13:00 (no sequence numbers reset) - Logout at 17:00
const int NumberOfSchedules = 2;
var schedules = new SessionSchedule[NumberOfSchedules];

// Schedule for the first part of the working day.
schedules[0] = new SessionSchedule(DayOfWeek.Monday, DayOfWeek.Friday, new TimeSpan(8, 0, 0), new TimeSpan(12, 0, 0), SessionDuration.Day, SequenceNumberResetPolicy.Daily);

// Schedule for the second part of the working day.
schedules[1] = new SessionSchedule(DayOfWeek.Monday, DayOfWeek.Friday, new TimeSpan(13, 0, 0), new TimeSpan(17, 0, 0), SessionDuration.Day, SequenceNumberResetPolicy.Never);

// Register two schedules for the same session.
scheduler.Register(session, schedules, new InitiatorConnectionSettings("localhost", 4500));
Note

If multiple schedules are used, set the sessionDuration parameter to the Day value and make sure that the logonTime is less than the logoutTime.

In this article
Back to top Copyright © Onix Solutions.
Generated by DocFX