Elektron SDK - C/C++

API Family: Elektron

EMA Consumer - Decoding MarketPrice data

Download tutorial source code

Click here to download

Last update June 2018
Compilers Tutorial demonstration: Visual Studio 2013

Refer to the EMA Compiler Guides for a complete list
Prerequisites Tutorial 2 - Requesting MarketPrice data

Introduction

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

Description

In previous tutorial we subscribed to Level 1 MarketPrice instrument "IBM.N", and used ema::access::Msg built in string translation, to display the message on 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 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

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

In 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 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 modelled using an OMM data structure called a FieldList. A FieldList is container of "field Id" and "field value" paired entries called FieldEntries. we will loop over all field entries and display the Key name on console followed by decoded data. The Key in a MarketPrice FieldList is a FID (Field Identifier). These FID's are neumeric numbers which are defined in data dictionary. For e.g. looking at etc\RDMFieldDictionary in EMA install folder, The FID for BID is 22. Other 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 other in the switch statement.



Figure 1: OMM FieldList

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 setup 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 application will connect, send subscription request and display decoded market price at the command line.

Connecting to market data server
Subscribing to market data

----------------------------------
Refresh message, item Handle: 3492304 Closure: 0000000000000000

Item Name: IBM.N
Service Name: ELEKTRON_AD
Item State: Open / Ok / None / 'All is well'
.
.
Fid: 6 Name: TRDPRC_1 DataType: Real Value: 168.21
Fid: 12 Name: HIGH_1 DataType: Real Value: 168.72
Fid: 13 Name: LOW_1 DataType: Real Value: 167.34
Fid: 22 Name: BID DataType: Real Value: 168.2
Fid: 25 Name: ASK DataType: Real Value: 168.31
.
.
.

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

Connecting to market data server
Subscribing to market data

Status message
Item Name: IBM.N, Service Name: ELEKTRON_DD
Stream state: 4 Status code: 3  Status text: Access Denied: User req to PE(62)
Tutorial Group: 
EMA Consumer