Skip to content

Configuring a session

Everything about one FIX session lives in a FixSessionSettings. This guide covers the settings you will need on the first day, then the ones you will need when a counterparty asks for something specific.

Every default quoted here is read from FixSessionSettings; the javadoc there is the authority.


The minimum

FixSessionId sessionId = FixSessionId.of(FixRegularVersion.VERSION_44, FixSessionId.FixSessionIdBuilder.builder()
        .name("initiator-session")
        .senderCompID("initiator")
        .targetCompID("acceptor")
        .build());

FixSessionSettings settings = FixSessionSettings.builder()
        .fixSessionId(sessionId)
        .fixSessionType(FixSession.FixSessionType.INITIATOR)
        .build();

Only two settings have no default: fixSessionId and fixSessionType. Everything else has a value chosen to be safe and cheap.

A FixSessionId is the FIX version plus the CompID pair. It is the identity of the session on the wire and the key the engine uses to find the right application, store and logger. Its name is unique only within its group, so two counterparties can each have a trading session; getQualifiedName() (group.name) is what is unique in the engine.


Wiring the session to the engine

Every pluggable component (store, logger, application factory, settings store, admin exporter, monitoring plugin) follows the same pattern: a …Settings builder handed to FixEngineBuilder, and an implementation chosen by which jar is on the classpath.

A session does not hold a store or an application; it holds the instance id of one. You register components on the engine under an id, and the session names the id it wants:

FixEngineBuilder.builder()
        .fixMessagesStore(MemoryMessageStoreSettings.builder().instanceId("acceptor").build())
        .fixApplicationFactory(SimpleApplicationFactorySettings.builder()
                .instanceId("acceptor")
                .application(sessionId.getQualifiedName(), myApplication).build())
        // …
FixSessionSettings.builder()
        .fixSessionId(sessionId)
        .fixSessionType(FixSession.FixSessionType.ACCEPTOR)
        .fixMessageStoreInstanceId("acceptor")
        .fixMessageLoggerInstanceId("acceptor")
        .fixApplicationFactoryInstanceId("acceptor")
        .fixApplicationInstanceId(sessionId.getQualifiedName())
        .build();
setting default what it selects
fixMessageStoreInstanceId DEFAULT_INSTANCE_ID which registered message store persists this session
fixMessageLoggerInstanceId DEFAULT_INSTANCE_ID which registered logger records it
fixAlertsPublisherInstanceId DEFAULT_INSTANCE_ID which registered alerts publisher its probes report to
fixApplicationFactoryInstanceId DEFAULT_INSTANCE_ID which factory produces its application
fixApplicationInstanceId DEFAULT_INSTANCE_ID which application within that factory

The instance ids default to the same id, so a single-session engine can leave them out. Once an acceptor and an initiator share a process, set them: this is what keeps their sequence numbers, logs and applications apart.

The FIX dictionary is not a setting: a session speaks its application's, FixApplication.getDictionaryId(). A session whose FIX version, or for FIXT its DefaultApplVerID, is not the application's is refused when its settings are saved and when it starts.


Sequence numbers and recovery

setting default notes
resetSeqNumOnLogon null true asks for a sequence reset on every logon. Convenient in development, rarely right in production
enabledLogonNextExpectedMsgSeqNum true uses NextExpectedMsgSeqNum(789) on the Logon to synchronise, which avoids a resend round trip
maxOutOfSequenceMessagesQueued 10_000 how many messages arriving ahead of the gap are held while recovering
maxOutgoingMessagesHeldDuringRecovery 1_000 how many of your own messages are held back while a resend is in flight
maxMessagesResentPerRequest 10_000 cap on one ResendRequest's answer
resendRequestRange CLOSED whether resend requests are asked for as a closed range or open-ended
resendRequestResponseTimeout 30 seconds how long an answer to your own ResendRequest may stop making progress before it is asked for again, then given up on. Duration.ZERO waits forever

resetSeqNumOnLogon(true) is what the quickstart uses so it can be run repeatedly without state. Production sessions usually want persistence and real recovery instead; see Stores and loggers.

While a resend is in flight, messages received beyond the gap wait for it, and so do your own outgoing messages. resendRequestResponseTimeout stops an answer that stalls half way (typically on a garbled message in the range) from blocking the session forever while heartbeats keep it looking healthy. It counts from the last message that advanced the recovery, so a slow but progressing resend never trips it. On expiry the missing range is requested once more; a second expiry logs the session out. The application then sees onResendRequestInitiated twice for one gap, and onResendRequestTerminated once.


Heartbeats, timeouts and schedules

setting default
heartBeatInterval HeartbeatInterval.builder().build()
logInOrOutResponseTimeout 10 seconds
disconnectMessagesFlushDeadline 2 seconds
desiredSessionState LOGGED_IN
sessionScheduleSettings see below

desiredSessionState is the state the engine works to maintain: leave it LOGGED_IN and an initiator reconnects and logs on by itself. LOGGED_OUT keeps the session down: an initiator does not dial, and an acceptor answers a Logon with a Logout saying why. FixSession.logoutPermanently() and logon() change it at run time.

Session schedules live in sessionScheduleSettings and decide when the session is allowed to be up: sessionSchedules, nonStopSchedules, a timeZone (default: the JVM's), a withinSessionTimeCheckInterval (1 second) and outsideSessionTimePreTriggerDelay (2 seconds), which is how much warning FixApplication#onPreOutsideSessionTime gets before the window closes.


Validation

Coming from another engine, this will surprise you: almost every check is off, because each one costs time on every message.

Enabled by default:

setting what it does
validateChecksum verifies the CheckSum(10) of every received message
validateFieldsHaveValues rejects tag= with an empty value
allowUndefinedTagsForMessage permits tags the dictionary does not define for that message type

Disabled by default, so turn on the ones your counterparty relationship needs:

setting what it does
validateRequiredFields rejects messages missing fields the dictionary marks required
validateFieldsOutOfOrder rejects header/body/trailer or repeating-group fields out of declared order
validateDuplicateTags rejects a tag repeated at the same level
validateCompId checks SenderCompID and TargetCompID against the session's configured values
validateBeginString checks BeginString(8) matches the session's FIX version
detectGarbledMessages the section 4.5.2 garbled-message conditions
allowUserDefinedFields permits user-defined tags absent from the dictionary
allowUnknownFields permits standard tags this dictionary does not define, which is how you talk to a peer on a later FIX version
maxSendingTime rejects and then logs out on a SendingTime(52) outside the tolerance, in either direction
FixSessionSettings.builder()
        .fixSessionId(sessionId)
        .fixSessionType(FixSession.FixSessionType.ACCEPTOR)
        .validationSettings(FixSessionSettings.ValidationSettings.builder()
                .validateRequiredFields(true)
                .validateCompId(true)
                .build())
        .build();

Two of these are about talking to someone on a different FIX version: allowUnknownFields covers standard tags your dictionary predates (the Global Technical Committee's 40000+ block, for instance) and allowUserDefinedFields covers the private range. Without them a peer on a newer version gets rejects for fields that are perfectly legal.

Third-party routing has two more: expectedOnBehalfOfCompIds and expectedDeliverToCompIds (both null = unchecked) restrict who the peer may send on behalf of, or address through you. A value outside the set is rejected with SessionRejectReason 9, CompID problem, without dropping the session.


Message size limits

setting default effect
maxMessageSize null advertised to the peer in MaxMessageSize(383) on the Logon, and used to reject oversized inbound messages
requiredPeerMaxMessageSize null the smallest MaxMessageSize you will accept from the peer; a smaller one ends the session with a Logout explaining why

Two more limits come from the connector rather than the session:

  • The largest message received is 1 MB by default. The read buffer starts at IOSettings.readBufferSize (8 KB) and grows for a larger message up to IOSettings.maxReadBufferSize, set on FixAcceptorBuilder.ioSettings or FixInitiatorBuilder.ioSettings (io-settings.max-read-buffer-size with Spring Boot). A message past it disconnects the session, with a session event and a warning naming the limit. Raise it for large security lists or market data snapshots.
  • A single field value is at most 2048 bytes, set with the staffix.FixMessageParser.maxFieldValueSize system property. A longer one stops the session.

Measuring round-trip time and clock offset

Set rttMeasurementSettings.probeInterval and the session continuously measures round-trip time and the peer's clock offset with TestRequest probes. Off by default. The settings, how to calibrate the offset and where the numbers surface are in Network monitoring.


Cancel on disconnect

Cancel on disconnect (COD) is the agreement that if the session goes away, resting orders should not be left working on the venue. It is not part of the FIX standard: it is a bilateral convention, negotiated on the Logon with user-defined fields, and every venue spells it slightly differently. So Staffix implements the mechanism and leaves the numbers configurable.

Staffix does not cancel anything. It negotiates the agreement, watches the session, and calls your application when the condition is met:

@Override
public void onCancelOnDisconnectTriggered(FixSession session, CancelOnDisconnectType type) {
    // pull your resting orders for this session
}

Cancelling is your side's job because only your application knows what an order is. The engine's job is to tell you, reliably and on time.

Turning it on

FixSessionSettings.builder()
        .fixSessionId(sessionId)
        .fixSessionType(FixSession.FixSessionType.INITIATOR)
        .cancelOnDisconnectSettings(FixSessionSettings.CancelOnDisconnectSettings.builder()
                .enabled(true)
                .cancelOnDisconnectType(CancelOnDisconnectType.CANCEL_ON_DISCONNECT_OR_LOGOUT)
                .codTimeoutWindow(Duration.ofSeconds(10))
                .build())
        .build();

enabled is false by default, and means different things on each side:

  • on an initiator: send the COD fields on the Logon, requesting the agreement;
  • on an acceptor: honour COD fields arriving on an inbound Logon.

What gets negotiated

setting default meaning
cancelOnDisconnectType CANCEL_ON_DISCONNECT_OR_LOGOUT which events trigger a cancel
codTimeoutWindow 10 seconds grace period before the trigger fires
codTimeoutWindowScale MILLISECONDS the unit the window is expressed in on the wire
cancelOnDisconnectTypeFieldCode 35002 tag carrying the type
codTimeoutWindowFieldCode 35003 tag carrying the window
cancelOnDisconnectTypeFieldCodes 0–3 as below wire value per type

The four types, and the characters they map to by default:

CancelOnDisconnectType wire value triggers on
DO_NOT_CANCEL_ON_DISCONNECT_OR_LOGOUT 0 nothing
CANCEL_ON_DISCONNECT_ONLY 1 an unexpected disconnect
CANCEL_ON_LOGOUT_ONLY 2 a clean logout
CANCEL_ON_DISCONNECT_OR_LOGOUT 3 either

Tags 35002 and 35003 are defaults, not a standard. They sit in the user-defined range precisely because no standard owns them, and your venue will very likely use different ones, so change cancelOnDisconnectTypeFieldCode and codTimeoutWindowFieldCode to whatever their specification says. The same applies to cancelOnDisconnectTypeFieldCodes if they encode the types with different characters.

You do not need allowUserDefinedFields(true) for this. Although these are user-defined tags, enabling COD registers exactly those two with the session's field registry, so they are known fields for this session and nothing else in the user-defined range is let in as a side effect.

The two asymmetries worth knowing

codTimeoutWindow means different things on each side. On an initiator it is the window sent in the Logon. On an acceptor it is the minimum acceptable window received, and a peer asking for less than you are prepared to honour is not silently accepted.

cancelOnDisconnectType is also the acceptor's fallback. If an inbound Logon carries no COD fields at all, an acceptor with enabled(true) still applies this value, which means COD can be in force for a counterparty that never asked for it. That is deliberate, and it is how you protect yourself from a peer who simply does not implement the convention. Set it to null to disable that fallback and honour only what the Logon actually requests.

Choosing the window

The window is a grace period, not a delay to be minimised. Too short and a brief network blip cancels a book that would have recovered on reconnect; too long and orders rest unmanaged after a real failure. It is a risk decision rather than a technical one, and it usually belongs to the same people who set your kill-switch thresholds.


When settings change under a running session

Settings can change while the session is up: through the admin API, a reload of the settings store, or a direct add/remove/update on the store.

An update does not interrupt a live session. The new settings are managed at once, and the running session keeps the ones it was created with until it next connects: a reconnection, its session time window reopening, or an operator's logout and logon. Nothing is applied in place, which is one rule rather than a list of which settings can be changed live and which cannot. Until then the session reports a pending update: FixSession.hasPendingSettingsUpdate(), and pendingSettingsUpdate in the HTTP admin API's status.

To apply an update now, ask for a restart: updateFixSessionSettings(sessionId, settings, true) on the admin API, or restart=true over HTTP. The live session is logged out and reconnects on the new settings.

A session that is not connected is rebuilt on the new settings at once. Either way an operator's logon or logout outlives the rebuild, unless the update changes desiredSessionState itself.

A removal stops the session: a live one is logged out and disconnected, whoever removed its settings.


Where settings come from

Everything above builds settings in Java. Two other sources exist:

  • YAML files, via the file session settings store, with a JSON schema generated at build time and shipped in the jar so your editor completes and validates the file. See the file-session-settings example.
  • Spring properties, via the Spring Boot starter, where sessions are declared entirely in application.properties. See the spring-boot-starter-example.

The settings model is the same in all three cases; only the transport differs. Session settings stores covers the stores that hold them: the memory store, and the file store with its default.yaml merge, classpath and URI sources, and ${...} placeholders.

Sessions declared in Spring properties need no placeholders of their own: Spring resolves ${...} in application.properties itself, from every property source it knows.