How to get Exchange Information from a Market Price Domain

Overview

For some instruments, suffix of RIC indicates the exchange where it is traded, e.g. HSBA.L (.L = LSE - London Stock Exchange), HBC.N (.N = NYSE - New York Stock Exchange). However, there are some instruments without the exchange code suffix like TWXF2Z7 (Time Warner DEC7), KC4F5Z7 (Kone Corp DEC7), etc. How can anĀ application know the exchange of those instruments?

Solution

Elektron provides a short exchange name information via the FID 1709 (Field name RDN_EXCHD2) for the Market Price domain. This FID 1709 is the enumeration field that used in most of the exchanges. The Elektron API 1.1.0 (EMA Java 3.1.0) and above can retrieve an enum value from dictionary directly, so it can help a consumer application get a short exchange name from this enumeration field.

RDMFieldDictionary

RDN_EXCHD2 "EXCHANGE ID 2"       1709  NULL        ENUMERATED    5 ( 3 )  ENUM             2

enumtype.def

RDN_EXCHD2  1709
...
! VALUE      DISPLAY   MEANING
! -----      -------   -------
      0        "   "   undefined
      1        "ASE"   NYSE AMEX
      2        "NYS"   New York Stock Exchange
      3        "BOS"   Boston Stock Exchange
      4        "CIN"   National Stock Exchange (formerly Cincinnati Stock Exchange)
      5        "PSE"   NYSE Arca
      6        "XPH"   NASDAQ OMX PSX when trading in SIAC (formerly Philadelphia Stock Exchange)
    ...
      1454     "PCW"   PetroChem Wire LLC
      1455     "SMP"   Euronext - Smartpool
      1456     "BT1"   BATS ONE - LEVEL 1 (PRODUCT)

Solution Code

This 1709 FID is an enumeration field type consisting of a set of mnemonics; each with its own specific meaning. A displayable string representing each exchange short name is associated with each of these mnemonics. Mapping between mnemonics and displayable string is required to get the suitable and meaningful exchange short name. The EMA Java 3.1.0 API can help the application gets an enumeration field value and map it to a displayable value with only a few lines of code.

Please see the ExchangeName example that modified from EMA Java's example360MarketPriceView to subscribe and handle FID 1709 below.

  1. Firstly, we create the OMM ElementList object to keep the OMM Payload and the OMM Array to keep interested FIDs in the ExchangeName class
public class ExchangeName{
      ...
      //View
      ElementList view = EmaFactory.createElementList();
      OmmArray view_array = EmaFactory.createOmmArray();
}
  1. Then we add the interested FIDs including 1709 to the OMM Array
public class ExchangeName{
      ...
      //View
      ElementList view = EmaFactory.createElementList();
      OmmArray view_array = EmaFactory.createOmmArray();


    view_array.fixedWidth(2);
      view_array.add(EmaFactory.createOmmArrayEntry().intValue(3)); //DSPLY_NAME
    view_array.add(EmaFactory.createOmmArrayEntry().intValue(22)); //BID
    view_array.add(EmaFactory.createOmmArrayEntry().intValue(25)); //ASK
      view_array.add(EmaFactory.createOmmArrayEntry().intValue(1709)); //RDN_EXCHD2
}
  1. Next, we add the OMM Array to the view ElementList by setting VIEW Type to 1 (FID) and VIEW Data to the array
public class ExchangeName{
      ...
      //View
      ...
      view.add(EmaFactory.createElementEntry().uintValue(EmaRdm.ENAME_VIEW_TYPE, 1));
      view.add(EmaFactory.createElementEntry().array(EmaRdm.ENAME_VIEW_DATA, view_array));
}
  1. Next, we create the ReqMsg object and set the view ElementList as a request's payload. EMA Java will send a snapshot item request (non-streaming) to Advanced DistributionĀ Server (ADS) with the View feature.
public class ExchangeName{
      ...
      //View
      ...
      view.add(EmaFactory.createElementEntry().uintValue(EmaRdm.ENAME_VIEW_TYPE, 1));
      view.add(EmaFactory.createElementEntry().array(EmaRdm.ENAME_VIEW_DATA, view_array));

      consumer.registerClient(EmaFactory.createReqMsg()
                            .serviceName("ELEKTRON_DD")
                            .name("TRI.N")
                            .interestAfterRefresh(false)
                            .payload(view)
                    , appClient);
}
  1. In the OmmConsumerClient application code, we implement the decode function that iterates incoming data FieldList in the onRefreshMsg and onUpdateMsg callbacks
class AppClient implements OmmConsumerClient
      public void onRefreshMsg(RefreshMsg refreshMsg, OmmConsumerEvent event){
            ...
            if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType())
                  decode(refreshMsg.payload().fieldList());
      }
}
  1. We implement the decode function to handle and print out DataTypes.ENUM, so the application will get FID 1709 enumerate value (enumtype.def) automatically.
class AppClient implements OmmConsumerClient
      public void onRefreshMsg(RefreshMsg refreshMsg, OmmConsumerEvent event){
            ...
            if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType())
                  decode(refreshMsg.payload().fieldList());
      }
      ...
      void decode(FieldList fieldList){
            for (FieldEntry fieldEntry : fieldList){
            System.out.print("Fid: " + fieldEntry.fieldId() + " Name = " + fieldEntry.name() + " DataType: " + DataType.asString(fieldEntry.load().dataType()) + " Value: ");

            if (Data.DataCode.BLANK == fieldEntry.code())
                System.out.println(" blank");
            else
                switch (fieldEntry.loadType()){
                              ...
                              case DataTypes.ENUM: //Handle FID 1709
                                    System.out.println(fieldEntry.hasEnumDisplay() ? fieldEntry.enumDisplay() : fieldEntry.enumValue());
                                    break;
                              case DataTypes.RMTES: //Handle FID 3
                                    System.out.println(fieldEntry.rmtes());
                                    break;
                              ...
                        }
      }
}

Running the application

The application source code is available at GitHub. You can get it via the following git command

$>git clone git@github.com:TR-API-Samples/Article.EMA.Java.ExchangeShortName.git

Note: The application works with EMA Java 3.1.0 (Elektron SDK 1.1.0) and above which supports the enum parsing only.

You can build the application and run it via the following steps

  1. Copy all required EMA Java 3.1.0 API libraries to the "libs" folder. The required libraries are as follows:
    • ema.jar (<Elektron SDK Java package>/Ema/Libs)
    • upa.jar (<Elektron SDK Java package>/Eta/Libs)
    • upaValueAdd.jar (<Elektron SDK Java package>/Eta/Libs)
    • commons-configuration-1.10.jar (<Elektron SDK Java package>/Ema/Libs/apache)
    • commons-lang-2.6.jar (<Elektron SDK Java package>/Ema/Libs/apache)
    • commons-logging-1.2.jar (<Elektron SDK Java package>/Ema/Libs/apache)
    • org.apache.commons.collections.jar (<Elektron SDK Java package>/Ema/Libs/apache)
    • slf4j-api-1.7.12.jar (<Elektron SDK Java package>/Ema/Libs/SLF4J/slf4j-1.7.12)
    • slf4j-api-1.7.12.jar (<Elektron SDK Java package>/Ema/Libs/SLF4J/slf4j-1.7.12)
  1. Install and configure Apache ANT in your machine
  1. Configure the Channel_1 of EmaConfig.xml file to specify the host name of the server (the TREP or Elektron platform) to which the EMA connects. This is for setting values of the node. This value can be a remote host name or IP address.
  1. You can change the requested service and item name in the following line of code to match your environment
consumer.registerClient(EmaFactory.createReqMsg().serviceName("<service>").name("<item name>").interestAfterRefresh(false).payload(view), appClient);
  1. Build the application with ant command. All application class files will be available at "out" folder, the EmaConfig.xml also copied to the out folder automatically.
$>ant build
  1. Inside the "out" folder, run the application with the following command
java -cp .;..\libs\ema.jar;..\libs\upa.jar;..\libs\upaValueAdd.jar;..\libs\org.apache.commons.collections.jar;..\libs\commons-configuration-1.10.jar;..\libs\commons-lang-2.6.jar;..\libs\commons-logging-1.2.jar;..\libs\slf4j-api-1.7.12.jar;..\libs\slf4j-jdk14-1.7.12.jar; com.thomsonreuters.platformservices.article.ExchangeName
  1. The example output when you run the application for each item name:
//TRI.N
Item Name: TRI.N
Service Name: ELEKTRON_DD
Item State: Non-streaming / Ok / None / 'All is well'
Fid: 3 Name = DSPLY_NAME DataType: Rmtes Value: THOMSON REUTERS
Fid: 22 Name = BID DataType: Real Value: 43.65
Fid: 25 Name = ASK DataType: Real Value: 43.66
Fid: 1709 Name = RDN_EXCHD2 DataType: Enum Value: NYS //FID value: 2          "NYS"   New York Stock Exchange

//KC4F5Z7
Item Name: KC4F5Z7
Service Name: ELEKTRON_DD
Item State: Open / Ok / None / 'All is well'
Fid: 3 Name = DSPLY_NAME DataType: Rmtes Value: Kone Corp DEC7
Fid: 22 Name = BID DataType: Real Value:  blank
Fid: 25 Name = ASK DataType: Real Value:  blank
Fid: 1709 Name = RDN_EXCHD2 DataType: Enum Value: EUX //FID value: 418        "EUX"   EUREX

//HSBA.L
Item Name: HSBA.L
Service Name: ELEKTRON_DD
Item State: Open / Ok / None / 'All is well'
Fid: 3 Name = DSPLY_NAME DataType: Rmtes Value: HSBC HOLDINGS
Fid: 22 Name = BID DataType: Real Value: 642.8
Fid: 25 Name = ASK DataType: Real Value: 642.9
Fid: 1709 Name = RDN_EXCHD2 DataType: Enum Value: LSE //FID value: 64        "LSE"   London Stock Exchange

Conclusion

If your application subscribes to data from Elektron Real Time Infrastructure and you need an exchange information, you can get it from the FID 1709 (RDN_EXCHD2). The EMA Java 3.1.0 API (Elektron API 1.1.0) can help an application consume and parse this FID to get an exchange shortname with only a few lines of code.

References

For further details, please check out the following resources: