FIX Session Initiator

Create

To create a session, call the following method:
Engine::Session* Engine::FixEngine::createSession(Engine::Application* apApp, const std::string& aSenderCompID, const std::string& aTargetCompID, 
    Engine::FIXVersion aVer = FIX42, Engine::SessionExtraParameters* pParam = NULL, const Engine::MessageStorageType storageType = persistent_storageType)

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

For example:

#include <iostream>
#include <B2BITS_V12.h>
   
using namespace std;
   
class Appl : public Engine::Application {
// See "Application description" section
};

try {
    // initialization
    Engine::FixEngine::init(); 
   
    Appl appl; 

    // create a session for FIX 4.2
    Engine::Session* pSn = Engine::FixEngine::singleton()->createSession(
        &appl, "SENDER", "TARGET", Engine::FIX42); 
   
    // establish the session as initiator
    pSn->connect(30, "localhost", 9106)
   
    // ... - business logic 
 
    // terminate the FIX session
    pSn->disconnect(); 
   
    // it is vital to do this before the 'release' call
    pSn->registerApplication(NULL);    
    
    // release resources
    pSn->release(); 
    FixEngine::destroy(); 
} catch(const Exception& ex) {
    cout << "EXCEPTION: " << ex.what() << endl;
}

Establish connection

After Engine::Session::connect is called initiator starts attempts to establish FIX session in a background. The following scenario is executed:

There is no need to wait until connection is established to send messages. If connection is not established messages will be sent later after connection process succeeds (for more information refer to Late delivery vs rejecting).

Custom Logon message

It is possible to customize Logon message to be sent by initiator during connection process. To use custom Logon message the method void Engine::Session::connect(int HBI, const FIXMessage& logonMsg, const std::string& host, int port) is to be used.

For example:

Appl appl; // : see the Application class above
Engine::FIXVersion version = Engine::FIX42;

// create session
Engine::Session* pSession = Engine::FixEngine::singleton()->createSession(&appl, "sender", "target", version); 
  
// create Logon message framework
Engine::FIXMessage* pLogonMsg = Engine::FIXMsgFactory::singleton()->newLogonSkel(version);
  
// sets fields
pLogonMsg->set(Engine::FIXField::MaxMessageSize, 20000); // tag 383  

// establishes the session as initiator
pSession->connect(0, *pLogonMsg, "localhost", 9105);

Reconnect

Initiator is responsible for restoring connection once it is broken. When connection error is detected initiator moves to "Reconnect" state and starts reconnection process. The foillowing scenario is executed:
  1. Establish telecommunication link
  2. Send Logon message
  3. Repeat from 1 if 1 or 2 fails
  4. Stop trying if attempts are over

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

Disconnect

To disconnect initiator (process can be also called "terminate", "delete", "close") the following methods can be used:

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

Release

To release a session's resources the Engine::Session::release() method is used.

It is vital to call Engine::Session::registerApplication(NULL) before calling the release method.

It is vital to call the Engine::Session::release() method only once for the given session.

Send message

To send outgoing application-level messages, use the Engine::Session::put(Engine::FIXMessage *) method.

All session level messages are send automatically when needed.


Generated on Fri Apr 17 12:26:09 2009 for B2BITS FIX Antenna C++ by  doxygen 1.5.6