FIX Antenna ANSI C  2.18.0
 All Data Structures Variables Pages
FIX Session Initiator

Creating FIX session initiator

Call the following method to create a session:

B2BITS_Session B2BITS_FixEngine_CreateSession(B2BITS_Application* apApp, const char* aSenderCompID, const char* aTargetCompID,
B2BITS_FIXVersion aVer, B2BITS_SessionExtraParameters* pParam, const B2BITS_MessageStorageType storageType)

After the session is created, use one of the methods below to connect to it as an initiator.

For example:

// Create Application instance - FIX session observer
// init function pointers with call-back functions.
app.Process = &App_Process;
app.OnLogonEvent = &App_OnLogonEvent;
app.OnLogoutEvent = &App_OnLogoutEvent;
app.OnHeartbeatWithTestReqIDEvent = &App_OnHeartbeatWithTestReqIDEvent;
// Create FIX session instance
pSI = B2BITS_FixEngine_CreateSession(
&app,
&initiatorCtx,
"Target",
"Sender",
B2BITS_FIX44,
0,
B2BITS_transient_storageType,
B2BITS_FIX_TCP
);
if(!pSI)
{
printf( "Error: %s\n", B2BITS_GetLastErrorDescription() );
return 1;
}
// Connect session as initiator
B2BITS_Session_ConnectInitiator(pSI,30, "127.0.0.1", 9105, B2BITS_EM_NONE, 0, B2BITS_AC_PRIMARY_CONNECTION);
// ... - business logic
// terminates the FIX session
B2BITS_Session_Disconnect(pSA);
// it is vital to do this before the 'release' call
B2BITS_Session_RegisterApplication(pSA, NULL, NULL, 1, 0);
// releases resources
B2BITS_Session_Release(pSA);
B2BITS_FixEngine_Destroy();

Establish connection

After B2BITS_Session_ConnectInitiator is called the initiator attempts to establish a FIX session in the background. The following scenario is executed:

Reconnecting

The initiator is responsible for restoring connection once it is broken. When connection error is detected the initiator moves to the "Reconnect" state and starts a reconnection process. The following scenario is executed:

  1. Establish telecommunication link
  2. Send Logon message
  3. Repeat from 1 if 1 or 2 fails
  4. Stop trying if the admissible number of attempts is exceeded

The number of reconnection attempts and delay can be set in the properties file (see Reconnect.MaxTries and Reconnect.Interval). Refer to Configuration for more details.

Disconnecting

Use the following methods to disconnect the initiator (this process can be also called "terminate", "delete", "close"):

aMarkAsTerminated parameter is used to set the desired state after disconnection. If it is set to "true" the initiator tries to disconnect gracefully (i.e. execute logout procedure). If it is set to "false" the initiator moves to the non-gracefully terminated state.

Releasing resources

Use the Engine::Session::release() method to release the allocated resources.

It is vital to call B2BITS_Session_RegisterApplication(pSA, NULL, NULL, 1, 0) before calling the release method.

It is vital to call the B2BITS_Session_Release(B2BITS_Session sn) method only once for the given session.

Send message

To send outgoing application-level messages, use the B2BITS_Session_Put(B2BITS_FIXMessage msg) method.

All session level messages are send automatically when needed.