OnixS C++ FIX Engine 2.79.1.0
Message Sequence Numbers

Understanding Message Sequencing

A single FIX session can exist across multiple sequential (not concurrent) physical connections. Parties can connect and disconnect multiple times while maintaining a single FIX session. That is, once OnixS::FIX::Session::logout method is called, the FIX Connection is terminated. However when the FIX Connection is terminated, the FIX session doesn't end its lifetime. It is possible to continue the session later using either OnixS::FIX::Session::logonAsAcceptor or OnixS::FIX::Session::logonAsInitiator methods again. In other words, FIX Session is comprised of one or more FIX connections.

All FIX messages are identified by a unique sequence number (the MsgSeqNum field) within the bounds of a single FIX session. Sequence numbers are initialized at the start of each FIX session starting at 1 (one) and increment throughout the session. Each session establishes an independent incoming and outgoing sequence series.

The OnixS C++ FIX Engine automatically synchronizes sequence numbers when reconnecting during a FIX session on the basis of the information previously stored in the Engine log files.

SequenceNumbers.gif

Manipulating Message Sequence Numbers

Monitoring sequence numbers enables parties to gracefully synchronize applications when reconnecting during a FIX session. To get the expected sequence number of the next incoming message the OnixS::FIX::Session::getInSeqNum member is exposed as well as OnixS::FIX::Session::getOutSeqNum member to get sequence number of the next outgoing message.

Resetting inbound and outbound message sequence numbers back to 1, for whatever reason, constitutes the beginning of a new FIX session. Method OnixS::FIX::Session::reset must be used to backup the previous log files and reset the sequence numbers to 1.

Note:
Both OnixS::FIX::Session::setInSeqNum and OnixS::FIX::Session::setOutSeqNum methods can be used to set expected sequence numbers manually before a FIX connection is established. However, it is NOT recommended to use these properties to reset the message sequence numbers to 1 for the session. Instead, method OnixS::FIX::Session::reset must be used.

Some implementations of the FIX protocol (FIX Dialects) expect that a FIX Session coincides with a FIX Connection. In other words, message sequence numbers must be reset back to 1 after the OnixS::FIX::Session::logout messages exchange and the FIX connection is terminated.

To interact with such FIX dialects, keepSequenceNumbersAfterLogout parameter of OnixS::FIX::Session::Session constructor should be set to false. In this case after the OnixS::FIX::Session::shutdown() method sequence numbers are set back to 1. Next time when the OnixS::FIX::Session object is created incoming and outgoing sequence numbers will start from 1 (in other words, a new FIX Session will be created).