As it is well-known, when a session is being established, it sends a Logon message, as it is defined by FIX Standard. However, in specific use contexts there may be a need to include additional information to the counterparty which is not specified by Standard. One of the common use case examples is when the counterparty requires authentication attributes like username and password. OnixS C++ FIX Engine supports this capability through the additional overload of the OnixS::FIX::Session class - OnixS::FIX::Session::logonAsInitiator.
- Note
- If you use a custom Logon in OnixS::FIX::Session::logonAsInitiator method then this custom Logon will also be used when the FIX Engine automatically attempts to recover the FIX connection after some network related issues.
Example
A lot of trading systems, based on version 4.2 of the FIX Protocol, require username (tag #553) and password (tag #554) fields to be included in the Logon message. Both fields do not exist in version 4.2 of the formal Standard. These fields were implemented in later versions of the FIX Protocol standards releases. The following sample demonstrates the solution for this typical situation. In particular, it sends the Logon message with the additional fields which are required by the counterparty.
using namespace OnixS::FIX::FIX43;
{
public:
void onInboundApplicationMsg(
Message & message,
Session *) ONIXS_FIXENGINE_OVERRIDE
{
std::clog
<< "Incoming application-level message: "
<< std::endl;
}
};
const std::string SenderCompID = "CustomLogonMessage_SND";
const std::string TargetCompID = "CustomLogonMessage_TRG";
const int Hbi = 30;
const std::string Username = "USER_NAME";
const std::string Password = "PASSWORD";
const std::string Host = "localhost";
SessionListener defaultListener;
Session initiator(SenderCompID, TargetCompID, Version, &defaultListener);
Message logonMsgWithAuthentication(OnixS::FIX::FIX40::Values::MsgType::Logon, Version);
logonMsgWithAuthentication.set(Tags::Username, Username)
.set(Tags::Password, Password);
initiator.logonAsInitiator(Host, Port, Hbi, &logonMsgWithAuthentication);