Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quickfix/n, most efficient way to extract message Type?

What is the most efficient way in Quickfix/n 1.4 to extract the message type as defined here: http://www.fixprotocol.org/FIXimate3.0/en/FIX.5.0SP2/messages_sorted_by_type.html

I currently use var msgType = Message.GetMsgType(message.ToString()); which results in "A" for a Logon message. Is there a better way? I try to determine the message type within ToAdmin(...) in order to catch an outgoing Logon request message so I can add the username and password.

I would love to do it through MessageCracker but so far I have not found a way to implement a catch-all-remaining message types in case I have not implemented all OnMessage overloads. (Please see related question: Quickfix, Is there a "catch-all" method OnMessage to handle incoming messages not handled by overloaded methods?).

Thanks

like image 952
Matt Avatar asked Jul 31 '13 09:07

Matt


2 Answers

Not your title question, but a key part of it:

I try to determine the message type within ToAdmin(...) in order to catch an outgoing Logon request message so I can add the username and password.

Here's a blob of code that pretty much nails it (taken from this post to the QF/n mailing list):

    public void ToAdmin(Message message, SessionID sessionID)
    {
        // Check message type
        if (message.Header.GetField(Tags.MsgType) == MsgType.LOGON)
        {
            // Yes it is logon message
            // Check if local variables YourUserName and YourPassword are set
            if (!string.IsNullOrEmpty(YourUserName) && !string.IsNullOrEmpty(YourPassword))
            {
                // Add Username and Password fields to logon message
                ((Logon) message).Set(new Username(YourUserName));
                ((Logon) message).Set(new Password(YourPassword));
            }
        }
    }
like image 115
Grant Birchmeier Avatar answered Nov 16 '22 11:11

Grant Birchmeier


In this case you could just do this inside ToAdmin:

var logonMessage = msg as Logon;
if (logonMessage != null)
{
    //Treat the logon message as you want
}

Or use the MessageCracker as explained in the other answer that you mentioned.

Hope it helps.

like image 24
natenho Avatar answered Nov 16 '22 10:11

natenho