Custom Logon Message
When a session-initiator is being established, it sends a standard Logon (A) message.
Sometimes there may be a need to include additional information for the counterparty which is not specified by the FIX Protocol Standard. One of the common use cases is when the counterparty requires authentication fields like username and password.
The Engine supports this use case via the LogonAsInitiator(string, int, int, bool, IMessage, bool) method.
For example:
// Primary version of FIX protocol used by the session.
const ProtocolVersion protocolVersion = ProtocolVersion.Fix44;
const string senderCompId = "SenderCompIdValue";
const string targetCompId = "TargetCompIdValue";
var initiator = new Session(senderCompId, targetCompId, protocolVersion);
const string host = "CountepartyHost";
const int port = 2000;
const int heartbeatInterval = 30;
const bool setResetSeqNumFlagInFirstLogon = false;
var customLogon = new Message(MsgType.Logon, protocolVersion);
const string userName = "UserNameValue";
const string password = "PasswordValue";
// Username and Password fields were first introduced in FIX 4.3,
// so the tag values should be taken from the OnixS.Fix.Fix43 namespace.
customLogon.Set(OnixS.Fix.Fix43.Tag.Username, userName)
.Set(OnixS.Fix.Fix43.Tag.Password, password);
initiator.LogonAsInitiator(host, port, heartbeatInterval, setResetSeqNumFlagInFirstLogon, customLogon);
Note
If you use a custom Logon message in the LogonAsInitiator(string, int, int, bool, IMessage, bool) method, then this custom Logon message will also be used when the Engine automatically attempts to recover the FIX connection after network related issues.