FIX Sessions | Table of Content | Subscribing to Session Events |
Understanding Session States |
During the FIX session lifetime, state changes occur. the Session class exposes the State property to determine in which state it currently resides.
The following table describes all possible FIX session states that can occur during its lifetime, as well as what a specific state means for a session with a particular role.
State | Session-Acceptor | Session-Initiator |
---|---|---|
DISCONNECTED | The session is disconnected. | The session is disconnected. |
LOGON_IN_PROGRESS | The session is waiting for the initial Logon message. | The initial Logon message was sent and the session is waiting for the acknowledgment Logon message. |
ACTIVE | The session is fully established (after the successful Logon exchange). | The session is fully established (after the successful Logon exchange). |
RECONNECTING | N/A (session can't reside in this state). | The Session is trying to restore the telecommunication link. |
LOGOUT_IN_PROGRESS | The initial Logout message was sent and the session is waiting for the acknowledgment Logout message. | The initial Logout message was sent and the session is waiting for the acknowledgment Logout message. |
Session class exposes StateChangeEvent for its users. Subscribing to this event provides an ability to be notified about all changes in the state of a particular session.
void OnStateChange(Object sender, StateChangeEventArgs args) { Console.WriteLine( "Session {0} changes its state from {1} to {2}.", sender, args.PrevState, args.NewState); } void run() { Session session = new Session("SenderCompID", "TargetCompID", ProtocolVersion.FIX44); session.StateChangeEvent += new Session.StateChangeEventHandler(OnStateChange); }
Sub OnStateChange(ByVal sender As Object, ByVal args As StateChangeEventArgs) Console.WriteLine("Session {0} changes its state from {1} to {2}.", sender, args.PrevState, args.NewState) End Sub Sub Run() Dim session As New Session("SenderCompID", "TargetCompID", FIXForge.NET.FIX.ProtocolVersion.FIX44) AddHandler session.StateChangeEvent, AddressOf OnStateChange End Sub