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.

See this code in PYTHON, RUBY

    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);
    }

## No Type Safety

Create your own fields using tag numbers.

See this code in PYTHON, RUBY

    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);
    }