Working With Messages
Receiving Messages
Most of the messages you will be interested in looking at will be arriving in your overloaded
fromApp
function of your application.
All messages have a header and a trailer.
If you want to see those fields, you must call
getHeader()
or
getTrailer()
on the message to access them.
Type safe Messages and Fields
QuickFIX has a class for all messages defined in the standard spec.
void fromApp( const FIX::Message& message, const FIX::SessionID& sessionID )
throw( FIX::FieldNotFound&, FIX::IncorrectDataFormat&, FIX::IncorrectTagValue&, FIX::UnsupportedMessageType& )
{
crack(message, sessionID);
}
void onMessage( const FIX42::NewOrderSingle& message, const FIX::SessionID& )
{
FIX::ClOrdID clOrdID;
message.get(clOrdID);
FIX::ClearingAccount clearingAccount;
message.get(clearingAccount);
}
void onMessage( const FIX41::NewOrderSingle& message, const FIX::SessionID& )
{
FIX::ClOrdID clOrdID;
message.get(clOrdID);
// compile time error!! field not defined in FIX41
FIX::ClearingAccount clearingAccount;
message.get(clearingAccount);
}
void onMessage( const FIX42::OrderCancelRequest& message, const FIX::SessionID& )
{
FIX::ClOrdID clOrdID;
message.get(clOrdID);
// compile time error!! field not defined for OrderCancelRequest
FIX::Price price;
message.get(price);
}
In order to use this you must use the
MessageCracker
as a mixin to your application.
This will provide you with the
crack
function and allow you to overload specific message functions.
Any function you do not overload will by default throw an
UnsupportedMessageType
exception.
Define your application like this:
#include "quickfix/Application.h" #include "quickfix/MessageCracker.h" class MyApplication : public FIX::Application, public FIX::MessageCracker
Type safe Fields Only
Use the
getField
method to get any field from any message.
C++
void fromApp( const FIX::Message& message, const FIX::SessionID& sessionID )
throw( FIX::FieldNotFound&, FIX::IncorrectDataFormat&, FIX::IncorrectTagValue&, FIX::UnsupportedMessageType& )
{
// retrieve value into field class
FIX::Price price;
message.getField(price);
// another field...
FIX::ClOrdID clOrdID;
message.getField(clOrdID);
}
Python
import quickfix
def fromApp(self, message, sessionID):
price = quickfix.Price()
message.getField(price)
clOrdID = quickfix.ClOrdID()
message.getField(clOrdID)
Ruby
require 'quickfix_ruby' def fromApp(message, sessionID): price = Quickfix::Price.new() message.getField(price) clOrdID = Quickfix::ClOrdID.new() message.getField(clOrdID) end
No Type Safety
Create your own fields using tag numbers.
C++
void fromApp( const FIX::Message& message, const FIX::SessionID& sessionID )
throw( FIX::FieldNotFound&, FIX::IncorrectDataFormat&, FIX::IncorrectTagValue&, FIX::UnsupportedMessageType& )
{
// retreive value into string with integer field ID
std::string value;
value = message.getField(44);
// retrieve value into a field base with integer field ID
FIX::FieldBase field(44, "");
message.getField(field);
// retreive value with an enumeration, a little better
message.getField(FIX::FIELD::Price);
}
Python
import quickfix
def fromApp(self, message, sessionID):
field = quickfix.StringField(44)
message.getField(field)
Ruby
require 'quickfix_ruby' def fromApp(message, sessionID): field = Quickfix::StringField.new(44) message.getField(field) end