Send and Receive Message from FIX Server using QuickFIX/J

In this tutorial, we will use QuickFIX/J to connect to a remote FIX server and send a Logon message.


Prerequisites

You will need the following dependencies:

  • JDK 1.6.0
  • log4j-1.2.15.jar
  • quickfixj-all-1.5.2.jar
  • slf4j-api-1.6.3.jar
  • mina-core-1.1.7.jar

Step 1: Configure Session Settings

Create a file named:

sessionSettings.txt

Copy the following configuration into it:

[DEFAULT]
# Settings which apply to all the Sessions.
ConnectionType=initiator
LogonTimeout=30
ReconnectInterval=30
ResetOnLogon=Y
FileLogPath=C:\Work\QuickFIXJ\logs

[SESSION]
# Settings specifically for one session
BeginString=FIX.4.2
SenderCompID=THIS VALUE IS THE CLIENT ID
TargetCompID=THIS VALUE IS THE FIX SERVER ID
StartDay=sunday
EndDay=friday
StartTime=00:00:00
EndTime=00:00:00
HeartBtInt=30
CheckLatency=N
MaxLatency=240
SocketConnectPort=PORT NUMBER OF THE SERVER
SocketConnectHost=IP ADDRESS OF YOUR SERVER
UseDataDictionary=Y
DataDictionary=C:\Work\QuickFIXJ\datadictionary\FIX42.xml
FileStorePath=C:\Work\QuickFIXJ\sessioninfo

Explanation of Important Parameters

ConnectionType

Specifies whether you are creating:

  • initiator → Client
  • acceptor → Server

LogonTimeout

Time (in seconds) before session expires.

ReconnectInterval

Time (in seconds) before reconnecting.

ResetOnLogon

Resets sequence numbers on every logon if set to Y.

BeginString

Specifies FIX version (e.g., FIX.4.2).

HeartBtInt

Heartbeat interval in seconds.

SocketConnectHost / SocketConnectPort

IP and port of FIX server.

FileStorePath

Location where session state is stored.


Step 2: Implement the Application Interface

Every FIX application must implement the Application interface.

public class TestApplicationImpl extends MessageCracker implements Application {

    @Override
    public void onCreate(SessionID sessionId) {
        System.out.println("Session created: " + sessionId);
    }

    @Override
    public void onLogon(SessionID sessionId) {
        System.out.println("Logged on: " + sessionId);
    }

    @Override
    public void onLogout(SessionID sessionId) {
        System.out.println("Logged out: " + sessionId);
    }

    @Override
    public void fromAdmin(Message message, SessionID sessionId) {
        System.out.println("Admin message received: " + message);
    }

    @Override
    public void fromApp(Message message, SessionID sessionId) {
        System.out.println("Application message received: " + message);
    }
}

Step 3: Connect and Send Logon Message

public class TestQuickFixJConnectivity {

    public static void main(String[] args) {

        SocketInitiator socketInitiator = null;

        try {

            SessionSettings sessionSettings =
                new SessionSettings("C:\\Work\\QuickFixJ\\sessionSettings.txt");

            Application application = new TestApplicationImpl();

            FileStoreFactory fileStoreFactory =
                new FileStoreFactory(sessionSettings);

            FileLogFactory logFactory =
                new FileLogFactory(sessionSettings);

            MessageFactory messageFactory =
                new DefaultMessageFactory();

            socketInitiator = new SocketInitiator(
                application,
                fileStoreFactory,
                sessionSettings,
                logFactory,
                messageFactory
            );

            socketInitiator.start();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Sending Logon Request

private static void sendLogonRequest(SessionID sessionId)
        throws SessionNotFound {

    Logon logon = new Logon();

    logon.set(new HeartBtInt(30));
    logon.set(new ResetSeqNumFlag(true));

    boolean sent = Session.sendToTarget(logon, sessionId);

    System.out.println("Logon Message Sent: " + sent);
}

Conclusion

You have now:

  • Configured QuickFIX/J session settings
  • Implemented the Application interface
  • Connected to a FIX server
  • Sent a Logon message

You can extend this by handling execution reports, market data, and order flow.

Comments

Leave a Reply