![]() |
||||||||||||
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 FF.FIX Engine API 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. The following diagram presents an architectural view of a FF.FIX Engine based Initiator application: ![]() A FIX Initiator application based on FF.FIX Engine has the following components:
|
||||||||||||
The implementation of FIX Protocol occurs through FixSession objects. The Initiator class in the FF.Fix.Initiator namespace offers an abstraction over a FixSession object. The three important functions that control the behavior of an Initiator application are:
|
||||||||||||
The FixInitiatorHandler class provides a callback interface to listen important events and exchanged messages during a FIX session. You can create your own customized callback listening and processing mechanism as shown below: public class MyInitiatorCallbackListner : FF.Fix.Initiator.FixInitiatorHandler |
||||||||||||
An instance of the Initiator class needs a FixConfig object to manage the FIX session it holds. You can provide the required FixSession object by loading a FIX configuration file (XML) as follows: //Load a FIX configuration file |
||||||||||||
The initialization of persistence layer for the entire Initiator application is a one time process. It does not depend on the number of instances of the Initiator class. The FixDBConfig class provides the persistence layer the entire application. The following code snippet demonstrates creation of the persistence layer: string dbName = "FFFix"; /*FIX persistence database layer initialization (for MSSQL) using a valid connection string.*/ //Initialize the persistence layer for an application //This method has to be called once for an entire application. |
||||||||||||
Different instances of the Initiator class deal with different FIX connections (sessions). While initializing an instance of the Initiator class, the FixSession object appears in the parameter list for the Init() call. The following code shows how to extract a FixSession object associated with an instance of the Initiator class: /*A user can retrieve a valid FixSession object after a successful initialization of Initiator.*/ Initiator _initiator = null; _initiator = new Initiator(); |
||||||||||||
The FixAlertManager class contains a list of all FIX session alerts. You need to register to alerts of your choice for using them in FIX sessions held by your application. For example: //Register to listen to different session alerts. private void OnFIXSessionAlertMessage(SessionInfo fixSessionInfo, eAlertType alertType, string alertMessage, string additionalMessage) else if (alertType == eAlertType.OutboundMessageSeqNumber) else if (alertType == eAlertType.InboundMessage) else if (alertType == eAlertType.OutboundMessage) else if (alertType == eAlertType.SessionStateChange) else if (alertType == eAlertType.Info || alertType == eAlertType.Error || alertType |
||||||||||||
The steps for creating an Initiator application are as follows:
Step 1: Callback listener using System; { public override void OnSessionInitialize(FixSession fixSession) public override void OnEnrichSessionFixMessageHeader(FixSession fixSession,FixMessageHeader fixMessageHeader) public override void OnConnect(FixSession fixSession) public override void OnConnectionTimeOut(FixSession fixSession) public override void OnConnectionFailed(FixSession fixSession, string failedReason) public override void OnConnectionBreak(FixSession fixSession, string failReason) public override void OnInboundMessageMaximumLatencyTimeReached(FixSession fixSession, int latencyTime) public override void OnLogonTimeOut(FixSession fixSession) public override void SendingLogonMessage(FixSession fixSession, FixMessage logonMessage) public override void OnLogonMessage(FixSession fixSession, FixMessage message) public override void OnLogonMessageRejected(FixSession fixSession, FixMessage message) public override void OnLogoutMessage(FixSession fixSession, FixMessage message) public override void OnRejectMessage(FixSession fixSession, FixMessage message, int rejectedMessageSeqNum) public override void OnApplicationMessage(FixSession fixSession, FixMessage message) public override void InBoundQueueSizeThresoldValueReached(FixSession fixSession) public override void OnSessionTransmissionFail(FixSession fixSession, DateTime lastMessageRecvAt) Step 2: FIX Data Dictionary <?xml version="1.0" standalone="yes"?> <fixheader> <fixtrailer> <fixmessages> <fixmessage name="Logon" msgtype="A"> <repeatinggroup name="NoMsgTypes" required="N"> ... <fixfields> <fixfield tag="4" name="AdvSide" datatype="CHAR"> Step 3: FIX configuration file of Initiator type <?xml version="1.0" encoding="utf-8"?> <Session> <SessionActivationSchedule value="Weekly"> <StandardHeaderFieldValue> <MessageRecoveryRule> <Initiator> <SessionLogic> <SecureSSLProtocol UseSSLProtocol="N"> <Logger> <CustomAttribute> Step 4: Specify the FIX Data Dictionary in the FIX Configuration <?xml version="1.0" encoding="utf-8"?> <Initiator> ... Step 5: Start coding the Initiator application //Initializations and assignments. //Load a FIX configuration file. //creating a username for the user of the Initiator instance. //Create a FIX persistence connection string. //FIX persistence database layer Initialization (MSSQL) with a valid connection string. //Creating the Body part of the session initiating Logon message //Initialize the Initiator. //Start the Initiator. //Stop the Initiator. |
||||||||||||
You can pass Logon credentials to your counterparty in two ways: Method 1: For example: Initiator initiator = new Initiator(); FixMessageBody logonMsgBody = new FixMessageBody(); initiator.Start(); Method 2: The following code snippet shows how to customize SendingLogonMessage method for sending Logon credentials: class InitiatorCallbackListner: FixInitiatorHandler ... |
||||||||||||
The object oriented APIs in FF.FIX Engine use exception handling mechanism compliant with .NET compatible programming languages. They report all errors by raising a FixException. This enables you write the code that may look as follows (using C# syntax): try catch (FixException ex) This exception handling mechanism facilitates centralized error checking, keeps your mainline code readable and ensures that no error condition is ever ignored. |
||||||||||||
The AlertManager sends alerts about important events to the user registered callback methods using the threadPool thread. This thread is designed to use in short and focused tasks that shall not block. To prevent potential performance degradation of the overall system, all alert callback methods should be non-blocked or short lived. |
||||||||||||
To connect to your counterparty (Acceptor) over a SSL, make the following changes in the FIX configuration file.
For example: <SecureSSLProtocol UseSSLProtocol="Y"> |
||||||||||||