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
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));
}
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With