Session Management
Logon, logout, heartbeats, sequence numbers, and connection recovery for FIX 4.4.
Logon (MsgType = A)
The Logon message initiates a FIX session and authenticates the client.
Client → Server
| Tag | Field | Required | Description |
|---|---|---|---|
| 35 | MsgType | Yes | A |
| 49 | SenderCompID | Yes | Your assigned sender ID |
| 56 | TargetCompID | Yes | Brokeret's target ID |
| 34 | MsgSeqNum | Yes | Expected: 1 for new session |
| 52 | SendingTime | Yes | UTC timestamp |
| 98 | EncryptMethod | Yes | 0 (None) |
| 108 | HeartBtInt | Yes | Heartbeat interval in seconds (recommended: 30) |
| 553 | Username | No | Login username (if required) |
| 554 | Password | Yes | Authentication password |
| 141 | ResetSeqNumFlag | No | Y to reset sequence numbers |
Example
8=FIX.4.4|9=126|35=A|49=CLIENT1|56=BROKERET|34=1|52=20260312-14:30:00.000|98=0|108=30|553=client1|554=MyP@ssw0rd|141=Y|10=185|
Server → Client (Acknowledgment)
If authentication succeeds, the server responds with a Logon message confirming the session parameters.
| Tag | Field | Description |
|---|---|---|
| 35 | MsgType | A |
| 49 | SenderCompID | BROKERET |
| 56 | TargetCompID | Your SenderCompID |
| 108 | HeartBtInt | Confirmed heartbeat interval |
Logon Failure
If authentication fails, the server sends a Logout (5) message with the rejection reason in Tag 58 (Text):
8=FIX.4.4|9=82|35=5|49=BROKERET|56=CLIENT1|34=1|52=20260312-14:30:00.500|58=Invalid credentials|10=201|
Logout (MsgType = 5)
Gracefully terminates a FIX session.
Initiating Logout
Either side can initiate a logout:
| Tag | Field | Required | Description |
|---|---|---|---|
| 35 | MsgType | Yes | 5 |
| 58 | Text | No | Reason for logout |
Logout Sequence
- Initiator sends Logout message
- Counterparty responds with Logout message
- Both sides close the TCP connection
Heartbeat (MsgType = 0)
Heartbeat messages ensure the connection is alive. Both sides send heartbeats at the agreed interval.
| Tag | Field | Required | Description |
|---|---|---|---|
| 35 | MsgType | Yes | 0 |
| 112 | TestReqID | Conditional | Required if responding to a TestRequest |
Heartbeat Rules
- Each side sends a Heartbeat if no messages have been sent within the
HeartBtIntinterval - If no message is received within
HeartBtInt + reasonable delay, send a TestRequest - If no response to TestRequest within
HeartBtInt, consider the connection lost and disconnect
TestRequest (MsgType = 1)
Forces the counterparty to send a Heartbeat. Used to verify the connection is still active.
| Tag | Field | Required | Description |
|---|---|---|---|
| 35 | MsgType | Yes | 1 |
| 112 | TestReqID | Yes | Unique identifier (echoed back in Heartbeat response) |
Example
8=FIX.4.4|9=68|35=1|49=CLIENT1|56=BROKERET|34=15|52=20260312-14:35:00.000|112=TEST123|10=144|
The server responds with a Heartbeat containing TestReqID=TEST123.
ResendRequest (MsgType = 2)
Requests retransmission of messages when a sequence gap is detected.
| Tag | Field | Required | Description |
|---|---|---|---|
| 35 | MsgType | Yes | 2 |
| 7 | BeginSeqNo | Yes | First sequence number to resend |
| 16 | EndSeqNo | Yes | Last sequence number (0 = infinity, all subsequent) |
Example — Request Messages 5 Through 10
8=FIX.4.4|9=72|35=2|49=CLIENT1|56=BROKERET|34=4|52=20260312-14:35:30.000|7=5|16=10|10=156|
Gap Fill
The server may respond with a SequenceReset-GapFill for administrative messages that don't need resending:
8=FIX.4.4|9=78|35=4|49=BROKERET|56=CLIENT1|34=5|52=20260312-14:35:30.500|123=Y|36=8|10=170|
SequenceReset (MsgType = 4)
Resets the expected sequence number. Two modes:
GapFill Mode (Tag 123 = Y)
Used during resend to skip administrative messages:
| Tag | Field | Required | Description |
|---|---|---|---|
| 35 | MsgType | Yes | 4 |
| 123 | GapFillFlag | Yes | Y |
| 36 | NewSeqNo | Yes | New expected sequence number |
Reset Mode (Tag 123 = N or absent)
Used for emergency sequence number reset:
| Tag | Field | Required | Description |
|---|---|---|---|
| 35 | MsgType | Yes | 4 |
| 36 | NewSeqNo | Yes | New expected sequence number |
Reject (MsgType = 3)
Session-level rejection when a message cannot be processed.
| Tag | Field | Description |
|---|---|---|
| 35 | MsgType | 3 |
| 45 | RefSeqNum | Sequence number of the rejected message |
| 371 | RefTagID | Tag number causing the rejection |
| 372 | RefMsgType | MsgType of the rejected message |
| 373 | SessionRejectReason | Rejection reason code |
| 58 | Text | Human-readable description |
Session Reject Reason Codes
| Code | Meaning |
|---|---|
| 0 | Invalid tag number |
| 1 | Required tag missing |
| 2 | Tag not defined for this message type |
| 5 | Value is incorrect for this tag |
| 6 | Incorrect data format |
| 11 | Invalid MsgType |
| 13 | Tag appears more than once |
| 99 | Other |
Sequence Number Management
Best Practices
- Persist sequence numbers to disk to survive application restarts
- Use
ResetSeqNumFlag=Yon Logon only when explicitly agreed with Brokeret - Monitor for sequence gaps and issue ResendRequests promptly
- Keep a message store for potential resend requests from the server
Sequence Reset on Daily Rollover
Brokeret performs a daily sequence number reset at 00:00 UTC. Clients should expect:
- Server sends Logout at approximately
23:59:59 UTC - Client acknowledges with Logout
- Both sides reset sequence numbers to
1 - Client reconnects with
MsgSeqNum=1
Connection Recovery
Reconnection After Disconnect
- Reconnect TCP with the same
SenderCompIDandTargetCompID - Send Logon with the next expected outgoing sequence number
- If server detects a gap, it sends a ResendRequest
- If client detects a gap, it sends a ResendRequest
- Once synchronized, normal messaging resumes
Clean Start
To start fresh without resynchronizing:
- Send Logon with
ResetSeqNumFlag=Y(Tag 141) - Set
MsgSeqNum=1 - Server acknowledges and resets its own sequence numbers
Next Steps
- Market Data — Subscribe to streaming quotes
- Order Execution — Submit and manage orders