Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

Table of Contents

Preface

This page contains information about Decorators, also known as Object Model - convenient wrappers around raw, "flat" FixMessages. By using Decorators developers gain strongly typed access to all available properties of a message, that increases development speed (you write less code to read/write to message properties) and reduces the number of validation errors (because each decorated message class contains only properties that are relevant to this class).

...

To use Decorator you should:

  1. Generate decorator files for your set of dictionaries, as described in tools/decorator-generator/readme.txt;
    In examples below it is assumed that Decorator for standard FIX.4.4 is used and it's generated sources are placed

    to 

    in 'generated' folder,
    using following command: b2b_fix_msgs_generator2.exe -s FIX44 -a FIX44 -o ../generated -f ../../../data/fixdic44.xml
    Image Added
    Image Added

    Info
    titleNote

    In case of processing additional dictionary, the base dictionary should be place before additional one, e.g.:

    b2b_fix_msgs_generator2.exe -s FIX44 -a FIX44 -o ../generated -f ../../../data/fixdic44.xml ../../../data/additional_fix44.xml

  2. Either add files from generated/src and generated/headers folders to your project, or build shared/static library from them;
    1. Optional. Add a folder for your convenience.
      Image Added

    2. Add generated files to project:
      Image Added
      Image Added


    3. Add path to generated headers as additional include directory:
      Image Added
      Image Added
      Image Added

    4. Add regular FIX Antenna library as dependency:
      Image Added
      Image Added


    5. Add preprocessor definitions:
      1. In case you are incorporating decorator sources in your application or static library, or if you are using decorator static library in your application, please add V12_DECORATOR_IMPL preprocessor definition.
      2. In case you are building shared library from decorator sources please add V12_DECORATOR_EXPORTS.
      3. In case you are building application with use of shared library from case ii - you need no additional definitions.
      Image Added
  3. In your code add following includes:

    #include <FixMessages/FIX44/AllMessages.h>
    #include <FixMessages/FIX44/Tags.h>
    #include <FixMessages/FIX44/Enums.h>
    Image Added

  4. Done! Now you can find FIX.4.4 Decorator API under FixMessages::FIX44 namespace.

...

For example, if you have defined your custom dictionary like that:

Code Block
languagexml
themeConfluence
titleadditional_ms_42.xml
linenumberstrue
<fixdics>
 <update> 
  <fixdic fixversion="4.2" id="MS_FIX42" parent_id="FIX42" title="Morgan Stanley FIX 4.2" date="20170303" revision="0.0.0.1">
...
  </fixdic>    
 </update>   
</fixdics>

Then run command: b2b_fix_msgs_generator2.exe -s MS_FIX42 -a MS_FIX42 -f ../../data/fixdic42.xml ../../data/additional_ms_42.xml,

and your generated code will be placed under MS_FIX42 namespace.

...

You can convert decorator message object to flat FIXMessage using get() method.

Code Block
languagecpp
themeConfluence
titleExample.cpp
linenumberstrue
#include <FixMessages/FIX44/AllMessages.h>
#include <FixMessages/FIX44/Tags.h>
#include <FixMessages/FIX44/Enums.h>

using namespace FixMessages::FIX44;
//...

    NewOrderSingleMessage order;
    order.ClOrdID().set( "12304" );
    order.Side().set( '1' );
    order.Symbol().set( "MSFT" );
    order.TransactTime().set( UTCTimestampType::now() );
    order.OrderQty().set( 10 );
    order.OrdType().set( '2' );
    order.Price().set( 1.25 );
    order.check();
 
    cout << "To 'Buy 10 MSFT @ 1.25' use FIX message:" << endl
         << order.raw() << endl;

    pSession->put( order.get() );

Also please refer to BusinessScenariosExamples.cpp from samples/Decorator sample for more examples.

...

You can get message's fields using named field accessors.

Code Block
languagecpp
themeConfluence
titleExample.cpp
linenumberstrue
#include <FixMessages/FIX44/AllMessages.h>
#include <FixMessages/FIX44/Tags.h>
#include <FixMessages/FIX44/Enums.h>

using namespace FixMessages::FIX44;
//...
virtual bool Engine::Application::process(const Engine::FIXMessage & msg, const Engine::Session &aSn)
{
    if( MsgType::NEW_ORDER_SINGLE == msg.type() )
    {
        NewOrderSingleMessage order ( &msg );
        
        cout << "Got New Order - Single:" 
        << "  ClOrdID=" << order.ClOrdID().get()
        << "; Side=" << order.Side().get()
        << "; Symbol=" << order.Symbol().get()
        << "; TransactTime=" << order.TransactTime().get()
        << "; OrderQty=" << order.OrderQty().get()
        << "; OrdType=" << order.OrdType().get()
        << "; Price=" << order.Price().get()
        <<endl;
        
        // Don't forget to release flat FIXMessage 'msg', 
        // since it was provided by 'process' callback,
        // and it's memory is managed by Engine.
        order.release();
    }

    return true;
}

... Operate Repeating Groups with decorator?

...

Please see example below:

Code Block
languagecpp
themeConfluence
titleExample.cpp
linenumberstrue
#include <FixMessages/FIX44/AllMessages.h>
#include <FixMessages/FIX44/Tags.h>
#include <FixMessages/FIX44/Enums.h>

using namespace FixMessages::FIX44;
//...
    MarketDataRequestMessage req;
    req.MDReqID().set( "100112" );
    req.SubscriptionRequestType().set( SubscriptionRequestType::SNAPSHOT );
    req.MarketDepth().set( MarketDepth::FULL_BOOK );
    req.MDUpdateType().set( MDUpdateType::INCREMENTAL_REFRESH );
 
    MarketDataRequestMessage::MDEntryTypesGroupRef typeGrp = req.MDEntryTypes();
    typeGrp.resize( 2 );
    typeGrp[0].MDEntryType().set( MDEntryType::BID );
    typeGrp[1].MDEntryType().set( MDEntryType::OFFER );
 
    MarketDataRequestMessage::RelatedSymGroupRef relData = req.RelatedSym();
    relData.resize( 2 );
    relData[0].Symbol().set( "IBM" );
    relData[1].Symbol().set( "MSFT" );
 
    req.check();
 
    cout << "To 'Subscribe for Market Data updates' use FIX message:" << endl
         << req.raw() << endl;

Also please refer to BusinessScenariosExamples.cpp from samples/Decorator sample for more examples.

...