forwardAccepting FIX Session Without a Prior Creation of Session Object   Table of ContentLogon Password Authenticationforward
Connecting using Custom Logon Message

When a session 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 case examples is when the counterparty requires authentication attributes like username and password.

OnixS .NET Framework FIX Engine supports this capability through the additional overload of the Session class - LogonAsInitiator(String, Int32, Int32, Message).

Note Note

If you use a custom Logon in LogonAsInitiator(String, Int32, Int32, Message) 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

Many trading systems, that are based on version 4.2 of the FIX Protocol, require a 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 standard releases. The following sample demonstrates the solution to this typical situation. In particular, it sends the Logon message with the additional fields which are required by the counterparty.

C#
using FIXForge.NET.FIX;
using FIXForge.NET.FIX.FIX42;

// Primary version of FIX protocol used by the session.
const ProtocolVersion protocolVersion = ProtocolVersion.FIX42;

Session initiator = new Session(appSettings.SessionAttributes.SenderCompId, appSettings.SessionAttributes.TargetCompId, protocolVersion);

Message logonMsgWithAuthentication = new Message(MsgType.Logon, protocolVersion);

// Username as well as Password field was first introduced in FIX 4.3.
// Therefore tag value should be taken from a FIXForge.NET.FIX.FIX43 namespace.

logonMsgWithAuthentication.Set(FIXForge.NET.FIX.FIX43.Tags.Username, appSettings.Authentication.Username);

logonMsgWithAuthentication.Set(FIXForge.NET.FIX.FIX43.Tags.Password, appSettings.Authentication.Password);

initiator.LogonAsInitiator(appSettings.RemoteHost, appSettings.RemoteHostPort, appSettings.SessionAttribs.HBI, logonMsgWithAuthentication);
VB
Imports FIXForge.NET.FIX
Imports FIXForge.NET.FIX.FIX42

' Primary version of FIX protocol used by the session.
Dim protocolVersion As ProtocolVersion = ProtocolVersion.FIX42

Dim initiator As New Session(appSettings.SessionAttributes.SenderCompId, appSettings.SessionAttributes.TargetCompId, protocolVersion)

' Username as well as Password field was first introduced in FIX 4.3.
' Therefore tag value should be taken from a FIXForge.NET.FIX.FIX43 namespace.

Dim logonMsgWithAuthentication As New Message(MsgType.Logon, protocolVersion)

logonMsgWithAuthentication.Set(FIXForge.NET.FIX.FIX43.Tags.Username, appSettings.Authentication.Username)

logonMsgWithAuthentication.Set(FIXForge.NET.FIX.FIX43.Tags.Password, appSettings.Authentication.Password)

initiator.LogonAsInitiator(appSettings.RemoteHost, appSettings.RemoteHostPort, appSettings.SessionAttribs.HBI, logonMsgWithAuthentication)