Tag Archives: FIX

quickfix logon support for username password

QuickFix is an open source FIX engine.
Ive been doing a little simulator along the lines of this (but using zeromq+quickfix) to become familiar with FIX.

The ASX supports the Username and Password fields for Logon messages. Quickfix normally takes care of Logon for you, but does not support Username and Password as session settings. Im only interested in FIX 4.4 (as thats the highest the ASX supports), so ill restrict my code to dealing with that.

Because we are modifying outgoing Logon messages, normally we would use a message cracker from our Application::toAdmin() override.
But there is a bug in quickfix (1.13.3) that means that cracking non const message references calls the wrong code. It ends up calling the onMessage for the message const ref.
ie it calls

void MQFeederApplication::onMessage( const FIX44::Logon& m, const FIX::SessionID& sessionID)

instead of

void MQFeederApplication::onMessage( FIX44::Logon& m, const FIX::SessionID& sessionID)

Rather than showing how to fix that bug and the code you will use ill just code the message type check right into toAdmin(). If you were doing a real program youd fix the bug and do it properly.

Firstly the obvious. We need to inject the settings class into our application so that we can pull the username and password from the config file.

class MQFeederApplication
	: public FIX::Application,
	private FIX::MessageCracker
	MQFeederApplication(const FIX::SessionSettings&);
// ...
	const FIX::SessionSettings& settings;
// ...

and pass it to our Applications ctor:

int main(){
		FIX::SessionSettings settings( "../mqfeed.cfg" );
		MQFeederApplication app(settings);

Then in toAdmin we check the message type and pull the appropriate username and password from the settings

void MQFeederApplication::toAdmin( FIX::Message& message, const FIX::SessionID& sessionID)
	// when we send Logon make sure we add Username and Password if we have it configured for this session
	// I would have like to use a message cracker for this, but theres a bug in quickfix 1.13.3
	// wrt cracking non const messages
	const FIX::Dictionary& session_settings = settings.get(sessionID);
	if (FIX::MsgType_Logon == FIELD_GET_REF( message.getHeader(), MsgType)) {
		FIX44::Logon& logon_message = dynamic_cast<FIX44::Logon&>(message);
		if (session_settings.has("Username")) {
			FIX::Username username = session_settings.getString("Username");
			logon_message.set( username );
		if (session_settings.has("Password")) {
			FIX::Password password = session_settings.getString("Password");
			logon_message.set( password );

So far working with quickfix has been pretty easy.
I was initially surprised by the use of little class wrappers for each field type, but it means the compiler can check that you arent trying to set fields that arent supported.

		FIX44::Logon& logon_message = dynamic_cast<FIX44::Logon&>(message);

will result in a compile time error. neat.
If you do want to add custom fields you can either use Message::setField, or regenerate the code from a modified data dictionary.