EMA Consumer - Decoding MarketPrice data

Download tutorial source code

Click here to download

Last update Aug 2024
Compilers Tutorial demonstration: Visual Studio 2022
Prerequisites Tutorial 2 - Requesting MarketPrice data

Introduction

The goal of this tutorial is programmatically decoding the response received from API.

Description

In the previous tutorial, we subscribed to the Level 1 MarketPrice instrument "IBM.N", and used ema::access::Msg built-in string translation, to display the message on the console. Now we will modify the Consumer class and add code to decode the response. The market data is encapsulated in various OMM container classes, described in OMM White Paper. The level 1 data like BidAskTrade Price for any equity instrument, for e.g. IBM, are encapsulated in the OMM FieldList class. We already received callbacks from OMMConsumer, now we will programmatically decode the response.

Steps

  • Decode market data
  • Build and Run

Decode market data

The market price response message consists of an initial Image that contains all the fields, followed by Updates which contain only the fields which have changed since the last image or update. It also contains a status message which indicates the status of our request and upstream delivery system.

In the callback method for Refresh (Initial Image), we first dump the status of our request to console and then check if the data payload is an OMM FieldList. If it is, we pass that payload to the decode method which takes FieldList as an argument.

    	
            

void AppClient::onRefreshMsg( const RefreshMsg& refreshMsg, const OmmConsumerEvent& event) 

{

  .

  .

  .

  //  display the status of current request

  cout << endl << "Item State: " << refreshMsg.getState().toString() << endl;

  

  // Level1 data payload is encoded as an OMM FieldList or NoData if no payload data is available

  if( DataType::FieldListEnum == refreshMsg.getPayload().getDataType() )

    decode( refreshMsg.getPayload().getFieldList() );

}

OMM FieldList

MarketPrice RDM data is modeled using an OMM data structure called a FieldList. A FieldList is a container of "field Id" and "field value" paired entries called FieldEntries. we will loop over all field entries and display the Key name on the console followed by decoded data. The Key in a MarketPrice FieldList is a FID (Field Identifier). These FID's are numeric numbers that are defined in the data dictionary. For e.g. looking at etc\RDMFieldDictionary in the EMA install folder, The FID for BID is 22. Another part of FieldEntry is the value corresponding to that Key. Values can be any OMM Data types like DataType::RealEnum for floating-point numbers, DataType::IntEnum for integers, etc; or they can be complex OMM types like nested FieldList or a Map. Since MarketPrice model contains basic datatypes only, we will ignore all others in the switch statement.

Figure 1: OMM FieldLis

    	
            

void AppClient::decode( const FieldList& fl )

{

  while ( fl.forth() )

  {

    const FieldEntry& fe = fl.getEntry();

    cout << "Fid: " << fe.getFieldId() << " Name: " << fe.getName() << " Value: ";

    switch ( fe.getLoadType() )

    {

      case DataType::RealEnum :

        cout << fe.getReal().getAsDouble() << endl;

        break;

      .

      .

      .

      default :

        cout << endl;

        break;

  }

}

Build and Run

Assuming you have properly set up the Visual Studio project, you can now compile and run the tutorial. If you encounter any compile errors, ensure your environment variables are properly defined. When you run the tutorial, you should see no errors, and the application will connect, send a subscription request, and display decoded market price at the command line.

Example status message when this user is not permissioned to request data for IBM.N