Initiator
FIX Initiator
A FIX Initiator application is a Buy-side application that initially establishes a communication link with the FIX Acceptor application server (Sell-side) of the counterparty and then sends a session initiating Logon message to the FIX Acceptor application via the established communication link.
The QXFIX Engine API library makes it easy for you to develop an application that can act as a FIX Initiator and connect to the counterparty (Acceptor application’s server) and conduct sessions as per mutually agreed FIX specifications.
Components of Initiator Application
| Component details | Role in the Initiator application |
|---|---|
| Callback handler (FixInitiatorHandler) | Provides callback interface to listen to events |
| FIX configuration (FixConfig) | Represents FIX config XML |
| Persistence layer (FixDBConfig) | Handles DB persistence |
| FIX session (FixSession) | Manages FIX connection |
| Alert manager (FixAlertManager) | Handles alerts |
FAQs
- What is an Initiator?
- How do I define my own callback handling mechanism in my Initiator application?
- How do I configure my Initiator application for different FIX sessions?
- How do I create a persistence layer for my entire Initiator application?
- How do I extract a FixSession object associated with an instance of the Initiator?
- How do I register to different session alerts?
- How do I write my Initiator application?
- How do I pass Logon credentials?
- How do I handle exceptions?
- Can I block AlertManager callbacks?
- How do I use SSL?
1. What is an Initiator?
View Answer
The Initiator class provides abstraction over FixSession.
Key methods:
- Init() → initialize
- Start() → start session
- Stop() → stop session
2. How do I define my own callback handling mechanism?
View Answer
You can extend FixInitiatorHandler.
View Code
public class MyInitiatorCallbackListner : FixInitiatorHandler
{
// override methods
}
3. How do I configure my Initiator application for different FIX sessions?
View Answer
An instance of the Initiator class requires a FixConfig object.
You can load configuration using an XML file.
View Code
string configFile = "...//Initiator.config";
FixConfig fixConfig = new FixConfig(configFile);
4. How do I create a persistence layer for my entire Initiator application?
View Answer
Persistence layer initialization is a one-time process.
FixDBConfig provides persistence configuration.
View Code
string dbName = "FFFix";
string dbHostName = Dns.GetHostName();
string dbConnectionString = string.Format(
"Data Source={0};Initial Catalog={1};Integrated Security=SSPI;Pooling=true;Min Pool Size=0;Max Pool Size=100;Connect Timeout=30",
dbHostName, dbName
);
FixDBConfig dbConfig = new FixDBConfig(eDBProvider.SqlServer, dbConnectionString);
FixProcess.Instance.Init(dbConfig);
5. How do I extract a FixSession object associated with an instance of the Initiator?
View Answer
After initializing the Initiator, you can retrieve the FixSession.
View Code
using com.QX.FIXEngine;
using com.QX.FIXEngine.Initiator;
Initiator _initiator = null;
FixSession _fixSession = null;
_initiator = new Initiator();
_initiator.Init(...);
_fixSession = _initiator.GetFixSession();
6. How do I register to different session alerts?
View Answer
You can register for session alerts using FixAlertManager.
View Code
_fixSession.GetAlertManager().RegisterAlertCallback(
com.QX.FIXEngine.Core.eAlertType.All,
new AlertCallbackRoutine(OnFIXSessionAlertMessage)
);
private void OnFIXSessionAlertMessage(SessionInfo fixSessionInfo,
eAlertType alertType,
string alertMessage,
string additionalMessage)
{
if (alertType == eAlertType.InboundMessageSeqNumber)
{
SetControlText(this.txtInboundSequenceNumber, alertMessage);
}
else if (alertType == eAlertType.OutboundMessageSeqNumber)
{
SetControlText(this.txtOutboundSequenceNumber, alertMessage);
}
else if (alertType == eAlertType.InboundMessage)
{
SetControlText(this.rtbMessageLog, "INBOUND MESSAGE: " + alertMessage);
}
else if (alertType == eAlertType.OutboundMessage)
{
SetControlText(this.rtbMessageLog, "OUTBOUND MESSAGE: " + alertMessage);
}
else if (alertType == eAlertType.SessionStateChange)
{
SetControlText(this.txtSessionState, alertMessage);
}
else if (alertType == eAlertType.Info ||
alertType == eAlertType.Error ||
alertType == eAlertType.Warning)
{
SetControlText(this.rtbLog,
alertType.ToString().ToUpper() + ": " + alertMessage);
}
}
7. How do I write my Initiator application? What steps do I need to follow?
View Answer
The steps are:
- Create callback listener
- Create FIX Data Dictionary
- Create FIX configuration
- Link dictionary in config
- Start coding
Step 1: Callback listener
View Code
internal sealed class InitiatorCallbackListner : FixInitiatorHandler
{
public override void OnSessionInitialize(FixSession fixSession) { }
public override void OnConnect(FixSession fixSession) { }
public override void OnApplicationMessage(FixSession fixSession, FixMessage message) { }
}
Step 2: FIX Data Dictionary
View Code
<?xml version="1.0" standalone="yes"?>
<fixDataDictionary version="FIX.4.2">
<fixheader>
<fixfield name="BeginString" required="Y" />
<fixfield name="BodyLength" required="Y" />
</fixheader>
</fixDataDictionary>
Step 3: FIX Configuration
View Code
<configuration>
<Session>
<add key="ConnectionType" value="Initiator" />
<add key="HeartBtInt" value="30" />
</Session>
</configuration>
Step 4: Link Data Dictionary
View Code
<add key="DataDictionary" value="InitiatorDataDictionary.xml" />
Step 5: Initiator Application Code
View Code
Initiator _initiator = new Initiator();
string configPath = "config.xml";
FixConfig fixConfig = new FixConfig(configPath);
string userID = "Initiator1";
FixDBConfig dbConfig = new FixDBConfig(
eDBProvider.SqlServer,
"connection string"
);
_initiator.Init(userID, fixConfig, dbConfig, null);
_initiator.Start();
_initiator.Stop();
8. How do I pass Logon credentials to my counterparty?
View Answer
You can pass Logon credentials in two ways:
Method 1: During Init()
View Code
Initiator initiator = new Initiator();
FixMessageBody logonMsgBody = new FixMessageBody();
logonMsgBody.SetField(FixFieldTag.Password_554, "Pwd");
initiator.Init(userName, fixConfig, persistConfig, callbackHandler, logonMsgBody);
initiator.Start();
Method 2: Override SendingLogonMessage
View Code
class InitiatorCallbackListner : FixInitiatorHandler
{
public override void SendingLogonMessage(FixSession fixSession, FixMessage logonMessage)
{
logonMessage.SetField(FixFieldTag.Password_554, "Pwd");
}
}
9. How do I handle exceptions thrown by the QXFIX Engine library?
View Answer
QXFIX Engine uses FixException for error handling.
View Code
try
{
// Your code using QXFIX API
}
catch (FixException ex)
{
System.Console.WriteLine("Exception " + ex.Message);
}
This approach ensures centralized error handling and improves code readability.
10. Can I block a callback method of AlertManager for lengthy processing?
View Answer
No. AlertManager uses threadPool threads which are designed for short tasks.
Long blocking operations may degrade performance.
Key Points
- Keep callback methods lightweight
- Avoid long-running tasks
- Prevent blocking threads
11. How do I use SSL to connect to my counterparty?
View Answer
To enable SSL, update your FIX configuration file:
- Set UseSSLProtocol = Y
- Provide CNName
- Provide CertificateFile
View Code
<SecureSSLProtocol UseSSLProtocol="Y">
<add key="CNName" value="..." />
<add key="CertificateFile" value="..." />
<!--<add key="PrivateKeyFile" value="..." />
<add key="PrivateKeyPassword" value="..." />-->
</SecureSSLProtocol>