Creating FIX session initiator
Refer to the section FIX Session to read about sessions-initiators. To create session-initiator follow the 2-steps instruction below:
- Call one of the methods below to create a session:
Session *createSession(
Application *pApp,
const std::string& senderCompID,
const std::string& targetCompID,
FIXVersion ver,
const SessionExtraParameters* pParam = NULL,
const MessageStorageType storageType = persistentMM_storageType,
UnderlyingProtocol underlyingProtocolType = FIX_TCP);
Session *createSession(
Application *pApp,
const std::string& senderCompID,
const std::string& targetCompID,
ProtocolID protocolID,
FIXVersion ver,
const SessionExtraParameters* pParam = NULL,
const MessageStorageType storageType = persistentMM_storageType,
UnderlyingProtocol underlyingProtocolType = FIX_TCP);
- After the session is created, use one of the methods below to start session as initiator (session will immediately try to establish connection with counterparty i.e. establish telecommunication link, send FIX Logon message and wait for confirming FIX Logon message from counterparty):
virtual void connect(SessionRole sessionRole=NA_SESSION_ROLE, const SessionBackupParameters *pSessionBackupParameters=NULL)=0
Establishes the FIX session.
For example:
#include <iostream>
#include <B2BITS_V12.h>
};
try {
Appl appl;
pSn->
connect(30,
"localhost", 9106)
FixEngine::destroy();
} catch(const Exception& ex) {
cout << "EXCEPTION: " << ex.what() << endl;
}
Generic application interface.
Definition B2BITS_Application.h:82
Session * createSession(Application *pApp, const std::string &senderCompID, const std::string &targetCompID, FIXVersion appVer=NA, const SessionExtraParameters *pParam=NULL, const MessageStorageType storageType=default_storageType, UnderlyingProtocol underlyingProtocolType=FIX_TCP)
Creates a new FIX Session.
static FixEngine * init(InitParameters const ¶ms)
Initializes the Engine.
static FixEngine * singleton()
Returns an instance of this class.
FIX Session.
Definition B2BITS_Session.h:171
virtual Application * registerApplication(Application *pNewApplication, unsigned int delay=300, int maxTries=-1)=0
Registers Application.
virtual void disconnect(bool forcefullyMarkAsTerminated=false)=0
Initiates disconnect of the session.
virtual long release() const
Decrements reference counter.
@ FIX42
FIX 4.2.
Definition B2BITS_PubEngineDefines.h:81
Establish connection
After Engine::Session::connect is called the initiator attempts to establish a FIX session in the background. The following scenario is executed:
- Establishing the telecommunication link (TCP/IP)
- Sending FIX Logon message
- Waiting for a Confirm logon message
- Moving to the "Established" state There is no need to wait until the connection is established to send messages. If the connection is not established messages will be sent later, after the connection process succeeds (for more information refer to Late delivery vs rejecting).
Custom Logon message
It is possible to customize the Logon message to be sent by the initiator during connection process. Use the
method to send the custom Logon message.
For example:
Appl appl;
pLogonMsg->
set(Engine::FIXField::MaxMessageSize, 20000);
pSession->
connect(0, *pLogonMsg,
"localhost", 9105);
Basic FIX message.
Definition B2BITS_FIXMessage.h:82
virtual FIXMessage * newLogonSkel(FIXVersion ver) const =0
Creates the new skeleton of the Logon message and returns it.
static FIXMsgFactory * singleton()
Returns the instance of the class.
virtual bool set(int tag, MonthYear value)=0
Updates field value by tag number.
FIXVersion
FIX protocol version.
Definition B2BITS_PubEngineDefines.h:77
Reconnect
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:
- Establish telecommunication link
- Send Logon message
- Repeat from 1 if 1 or 2 fails
- Stop trying if the number of attempts exceeds limit specified in configuration
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.
Disconnect
Use the following methods to stop session-initiator (this process can be also called "terminate", "delete", "disconnect"):
- If "forcefullyMarkAsTerminated" is true, then the session will be marked as correctly terminated and persistent information about it will not be used during the subsequent connections.
Release resources
Use the Engine::Session::release() method to release the allocated resources.
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. There is no need to send session level messages (e.g. heartbeats), all session level messages are sent automatically when needed by the engine.
- Note
- It must be mentioned that it is highly NOT recommended to send the same message instance to the multiple sessions in parallel threads. Instead message must be duplicated (Engine::FIXMsgProcessor::clone) as many times as many sessions it is sent to.