Scheduling Session for Automatic Connection
The Sessions Scheduler service connects registered FIX sessions to counterparties at the beginning of the trading day and disconnects them at the end of a day.
It is also possible to keep a FIX Session connected for an entire trading week and disconnect it at the end of the last trading day.
The Sessions Scheduler is distributed as a stand-alone module.
Scheduler Class
The Scheduler is the main class of the Sessions Scheduler component.
Registering Session for Automatic Connection
The Register(Session, SessionSchedule, SessionConnectionSettings) member schedules a session for automatic login and logout per the given schedule.
For example:
SessionSchedule schedule = CreateSchedule();
scheduler.Register(session, schedule, new InitiatorConnectionSettings("localhost", 4500));
SessionSchedule CreateSchedule()
{
const int logonDelayInSeconds = 5;
TimeSpan logonTime = DateTime.Now.TimeOfDay.Add(new TimeSpan(0, 0, logonDelayInSeconds));
const int connectionDurationInSeconds = 30;
TimeSpan logoutTime = logonTime.Add(new TimeSpan(0, 0, logonDelayInSeconds + connectionDurationInSeconds));
return new SessionSchedule(DayOfWeek.Sunday, DayOfWeek.Saturday, logonTime, logoutTime, SessionDuration.Day, SequenceNumberResetPolicy.Daily);
}
Removing Session from Scheduling Services
The Unregister(Session) method removes the given session from the scheduling services.
Note
Unregister(Session) does not disconnect an active session. Therefore, if a session has been already connected by the scheduler, it remains connected after unregistering.
Handling Scheduling Warnings and Errors
The Scheduler class exposes the Error event to notify about scheduling errors (e.g., failure to establish the session after the configured number of attempts).
Note
Once the Error event is raised by the scheduler, all attempts to log on the disconnected session will be suspended till the next logon time.
The Scheduler class exposes the Warning event to provide information about non-critical schedule-related errors.
For example:
scheduler.Warning += (object sender, OnixS.Fix.Scheduling.SessionWarningEventArgs e) =>
{
Console.WriteLine($"Scheduler reported a warning for session {e.Session}: {e.Reason}");
};
scheduler.Error += (object sender, OnixS.Fix.Scheduling.SessionErrorEventArgs e) =>
{
Console.WriteLine($"Scheduler reported an error for session {e.Session}: {e.Reason}");
};
Failure at Logon
In case of failure at logon, the scheduler will raise the Warning event and try to perform logon again as per ReconnectAttempts and ReconnectInterval values.
If the session remains disconnected after the configured number of connection attempts, the scheduler will raise Error event and stop all subsequent attempts to connect the session until the next logon time.
Scheduling Algorithm
- If a session is registered during the time covered by the configured schedule, the scheduler will connect the session immediately.
- If a session is registered after the logout and before the logon time, no attempts will be made to connect the session until the next logon time.
- If a session is registered after the logout and before the logon time, and the session is in the Established state, it will be disconnected immediately.
- In case of a logon failure, the scheduler tries to logon again per its reconnection settings (ReconnectAttempts and ReconnectInterval values).
- In the TCP connection is broken, the FIX Engine tries to restore the connection per the ReconnectAttempts and ReconnectInterval values.
- If a session is re-connected within reconnection attempts defined by the session configuration settings, no error will be reported by the scheduler.
- In case of a graceful termination of the FIX Connection by the Logout message exchange before the scheduled logout time, the scheduler tries to log in the session again immediately.
- If a session is being reconnected and the logout time is reached, the scheduler will stop further reconnection attempts and no error will be reported.
Scheduling Log
The Scheduler class uses the NLog library.
Run-time and XML-based configurations
The Session Scheduler supports API- and XML-based descriptions of schedules and connection settings.
See Also
- Session Schedule
- Session Connection Settings
- XML-based Schedules and Connection Settings
- The SessionScheduler sample from the FIX Engine distribution package