FIX Session

Persistent session

All messages are saved in persistent storage.

Session data is stored to hard drive and can be restored after failure. The following session information is stored in this case:

Session state

From the moment of session creation to the moment of its termination the session uses a state that dictates its reaction to events. The session state can be obtained using the session.getSessionState() method, which returns SessionState.

Sequence number handling

A session always has two sequence numbers:

Both sides must maintain those two values and control their synchronization. There are two types of sequence numbers desynchronization:

Both sequence numbers are started from 1 when session is created from scratch. If connection is terminated, sequence numbers continue after restoration. A lot of service providers never reset sequence numbers during the day. The are also some, that reset sequence numbers once per week. There are several cases to handle such a deviation from the standard in FIX Antenna

Resetting sequence number

To reset sequence numbers simply set incomingSequenceNumber and outgoingSequenceNumber in SessionPropertiers to 1 or any other desired value. By default it is set to 0 (automatically restore sequence number). It is also possible to remove FIX session persistent files from logs directory. Since FIX Antenna stores session state in those files, absence of such files will be treated as session being created from scratch and thus sequence numbers will be set to 1. Files can be removed during the End-Of-Day or End-Of-Week procedure.

Session scheduling

Fix Antenna Java allow to sсhedule session start/stop action using syntax similar to UNIX cron daemon. The CRON expression consist from 5 fields separated by white space that represents a set of times. Each part is intended as:

  1. Minutes sub-pattern. During which minutes of the hour should the task been launched? The values range is from 0 to 59.
  2. Hours sub-pattern. During which hours of the day should the task been launched? The values range is from 0 to 23.
  3. Days of month sub-pattern. During which days of the month should the task been launched? The values range is from 1 to 31. The special value "L" can be used to recognize the last day of month.
  4. Months sub-pattern. During which months of the year should the task been launched? The values range is from 1 (January) to 12 (December), otherwise this sub-pattern allows the aliases "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov" and "dec".
  5. Days of week sub-pattern. During which days of the week should the task been launched? The values range is from 0 (Sunday) to 6 (Saturday), otherwise this sub-pattern allows the aliases "sun", "mon", "tue", "wed", "thu", "fri" and "sat".

The star wildcard character is also admitted, indicating "every minute of the hour", "every hour of the day", "every day of the month", "every month of the year" and "every day of the week", according to the sub-pattern in which it is used.
Every sub-pattern can contain two or more comma separated values ("59 11 * * 1,2,3,4,5").
Values intervals are admitted and defined using the minus character.("59 11 * * 1-5").
The slash character can be used to identify step values within a range. It can be used both in the form */c and a-b/c. The subpattern is matched every c values of the range 0,maxvalue or a-b.("*/5 * * * *").
Also it's possible to combine more scheduling patterns into one, with the pipe character ("0 5 * * *|8 10 * * *|22 17 * * *").

Schedule initiator session

Use ScheduledSessionParameters to build sessions:

ScheduledSessionParameters params = new ScheduledSessionParameters();
params.setFixVersion(FIXVersion.FIX42);
params.setHost("localhost");
params.setHeartbeatInterval(30);
params.setPort(777);
params.setSenderCompId("senderId");
params.setTargetCompId("targetId");
//start session every Monday at 10:30
params.setStartTimeExpr("30 10 * * 1");
//stop session every Friday at 18:00
params.setStopTimeExpr("0 18 * * 5");

ScheduledFIXSession newFIXSession = params.createNewFIXSession();
//start scheduler behaviour if StartTimeExpr/StopTimeExpr defined
newFIXSession.start();
//connect session imidiatelly
newFIXSession.connect();


//stop scheduled tasks for this session
newFIXSession.stop();

Schedule acceptor session

It's possible to allow incomming connection only during specified period of time. To use this feature you need to create instance of ScheduledFIXServer instead of FIXServer:

ScheduledFIXServer server = new ScheduledFIXServer();

// allow connections to this server every day at 8 AM
server.scheduleAllowSessions("0 8 * * *");
// deny connections to this server every day at 8 AM
server.scheduleDenySessions("0 20 * * *");

In addition you can specify activity period for concrete acceptor session. Then such session will not be affected by default rules:

// define session
SessionParameters details = new SessionParameters();
details.setSenderCompId("senderId");
details.setTargetCompId("targetId");

//start session every Monday at 7:30 AM
server.scheduleSessionStart("30 7 * * 1", details);
//stop session every Friday at 5 PM
server.scheduleSessionStop("0 17 * * 5", details);

Session qualifier

Session qualifier give user ability to create several sessions with the same SenderCompId and TargetCompId and to give ability to address these session by unique ID.
To establish several sessions with the same SenderCompId and TargetCompId, both Initiator and Acceptor should create several session objects which differ from each other by SessionQualifier property. SessionQualifier property on Initiator side must be the same as SessionQualifier property of the corresponding session on acceptor side. When Initiator connects to Acceptor, it sends SessionQualifier along with SenderCompId and TargetCompId in logon message. The SessionQualifier tag in logon message is optional and can be configured in fixengine.properties file. When Acceptor receives logon message with the SessionQualifier it searches for registered session with SessionId corresponding to received TargetCompId, SenderCompId and SessionQualifier.
The FIX engine will automatically insert SessionQualifier tag into logon message if user creates session with qualifier on initiator side and SessionQualifier tag is appropriately configured in fixengine.properties. To configure SessionQualifier tag user needs to add the lines like below to config file:

logonMessageSessionQualifierTag = 9012

To create session with qualifier you need set unique qualifier to SessionParameters:

// define session
SessionParameters details = new SessionParameters();
details.setSenderCompId("senderId");
details.setTargetCompId("targetId");
// set session qualifier
details.setSessionQualifier("1");
Generated on Wed Aug 22 17:11:17 2018 for FIXAntennaJava by  doxygen 1.6.3