DotNet, FIX

QuickFix: Connect multiple FIX sessions with Fix Server


 

This post will describe how we can connect multiple sessions with Fix Server. I’ll take example to connect Trade session and data session. Trade session is to send orders whereas data session is to get market prices from server.

To connect any Fix server we need to have some mandatory configuration like sender information, target information, server to connect, port, fix protocol version, connection type etc.

Below is table of mandatory configuration to connect Fix server:

 

Config Fields Description
ConnectionType it is to tell QuickFix engine it is acceptor (listener) or initiator(client).
BeginString Fix Protocol version eg. FIX.4.2
TargetCompID Target Server Id to connect
SenderCompID sender ID which will send message to target comp id
SocketConnectHost Fix Server IP address
SocketConnectPort Port to connect
Password Password to connect if needed

FixInitiator

To start any session with Fix server, there should be one class which will be inherited by QuickFix.Application base class.

Steps to connect Fix Server

image

 

 

Step 1: Add session information in Config file

Config.txt

[DEFAULT]
ConnectionType=initiator
HeartBtInt=20
ReconnectInterval=20
FileStorePath=c:\fixfiles
FileLogPath=log
StartTime=00:00:00
EndTime=00:00:00
UseDataDictionary=N

#trade session
[SESSION]
BeginString=FIX.4.2
TargetCompID=ABC
SenderCompID=demouser1
SocketConnectHost=127.0.0.1
SocketConnectPort=440
ResetOnDisconnect=Y
Password=1234

#data session

[SESSION]
BeginString=FIX.4.2
TargetCompID=ABC
SenderCompID=demouser2
SocketConnectHost=127.0.0.1
SocketConnectPort=441
ResetOnDisconnect=Y
Password=1234

Step 2: Load config file

var settings = new SessionSettings(config);
FileStoreFactory storeFactory = new FileStoreFactory(settings);
ScreenLogFactory logFactory = new ScreenLogFactory(settings);
QuickFix42.MessageFactory messageFactory = new QuickFix42.MessageFactory();

Step 3: Initiate Socket Initiator

  

SocketInitiator initiator = new SocketInitiator(ClientInitiator, storeFactory,

settings, logFactory, messageFactory);

Step 4: Connect

To connect to Fix Server you need to call Start  method of SocketInitiator class.

initiator.start();

 

Step 5: Enrich Logon message with mandatory fields

Before sending logon message to Fix server you need to fill some mandatory information. You can capture all the messages before sending to Fix server in toAdmin method in QuickFix.Application class (I have ClientInitiator class which is derive from QuickFix.Application class).

 
public void toAdmin(QuickFix.Message value, QuickFix.SessionID session)
        {
            if (value is QuickFix42.Logon)
            {
               var logon = (QuickFix42.Logon)value;
               logon.set(new EncryptMethod(0));
               logon.set(new HeartBtInt(30));
               logon.setString(554,"abc"); //set password
               logon.set(new ResetSeqNumFlag(true));//reset sequence of messages
            }
        }

 

Step 6:  Response from server

After sending logon message to server, server authenticate this message and sends response either Logon or LogOut message.

You can capture relevant messages and can keep status of each session. Sever should send failure reason in case of logout message (message type 5). you can get it from field type “text (58)”.

 

 public override void onMessage(QuickFix42.Logon message, SessionID session)
       {
          if (_sessionMap.ContainsKey(session.getSenderCompID()))
          {
            _sessionMap[session.getSenderCompID()].Status = "Connected";
          }
        }

 public override void onMessage(QuickFix44.Logout message, SessionID session)
       {
         if (_sessionMap.ContainsKey(session.getSenderCompID()))
          {
           _sessionMap[session.getSenderCompID()].Status = "Disconnected";
         }
      }

 

I used same code base which I used in my previous post “basic fix message implementation using quickfix”. You can download code from this post and can apply below code in it. Please let me know if you still face any problem to implement above steps.

Happy Coding Smile

Advertisements

5 thoughts on “QuickFix: Connect multiple FIX sessions with Fix Server

  1. I am sendig Logon request in wireshark it display me as fix packet but which we check the financal information error. Due error/messing missing beginString filed.
    [Missing BeginString field]
    [Severity level:error]
    [Group:Malformed]

    Can you please help how can i resolve this.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s