How to parse OMMMsg in a simple way

i run the example code ,and receive the next text:
AttribInfo
ServiceName: ELEKTRON_DD
ServiceId: 257
Name: JPY=
NameType: 1 (RIC)
Payload: 2081 bytes
FIELD_LIST
FIELD_ENTRY 1/PROD_PERM: 213
FIELD_ENTRY 2/RDNDISPLAY: 153
FIELD_ENTRY 3/DSPLY_NAME: MDM BANK MOW
FIELD_ENTRY 5/TIMACT: 07:31
FIELD_ENTRY 11/NETCHNG_1: 0.17
FIELD_ENTRY 12/HIGH_1: 108.91
FIELD_ENTRY 13/LOW_1: 108.68
FIELD_ENTRY 15/CURRENCY: JPY (392)
FIELD_ENTRY 17/ACTIV_DATE: 24 APR 2018
FIELD_ENTRY 19/OPEN_PRC: 108.69
FIELD_ENTRY 21/HST_CLOSE: 108.70
FIELD_ENTRY 22/BID: 108.87
FIELD_ENTRY 23/BID_1: 108.87
FIELD_ENTRY 24/BID_2: 108.86
FIELD_ENTRY 25/ASK: 108.88
FIELD_ENTRY 26/ASK_1: 108.88
FIELD_ENTRY 27/ASK_2: 108.89
what i want is like JSON format :
{"CURRENCY": "JPY","BID":"108.87","ASK":"108.88"}
I only want the three Fields "CURRENCY ,BID ,ASK", but the parse way is too hard to understand. I don't know how to fix the code.
Would you please give me a simply way to parse the OMMMsg?
Best Answer
-
Hello @peng.xiaoliang
RFA Java package provides the GenericOMMParser class which is
used to read and initialize dictionaries and parse any OMM messages. Hence, you
may modify GenericOMMParser class to get your preference fields from the response
and keep them in the map. Then, you can create them as your preference format
i.e. JSON. The example source code is here://Add the method to GenericOMMParser.java to get CURRENCY, BID and ASK field
public static HashMap<String,String> parseOMMData(OMMData data)
{
HashMap<String,String> preferredFields = new HashMap<String,String>();
String valueStr;
if(CURRENT_DICTIONARY==null)
//make sure that RDMdictionary is loaded already
CURRENT_DICTIONARY = getDictionary(1);
for (Iterator iter = ((OMMIterable)data).iterator(); iter.hasNext();)
{
OMMEntry entry = (OMMEntry)iter.next();
if(entry.getType()==OMMTypes.FIELD_ENTRY) {
OMMFieldEntry fe = (OMMFieldEntry)entry;
FidDef fiddef = CURRENT_DICTIONARY.getFidDef(fe.getFieldId());
OMMData aValue = null;
if(fe.getFieldId() == 22 || fe.getFieldId()==25) {
//BID or ASK field
aValue= fe.getData(fiddef.getOMMType());
if(!aValue.isBlank())
//not blank value, get value as a String
valueStr = aValue.toString();
else
valueStr = ""; //otherwise, set blank value
preferredFields.put(fiddef.getName(), valueStr);
}
else if(fe.getFieldId() == 15)//CURRENCY which is enum type
{
aValue=fe.getData(fiddef.getOMMType());
if(!aValue.isBlank())
//not blank value, get String of the enum value
valueStr=CURRENT_DICTIONARY.expandedValueFor((short)15, ((OMMEnum)aValue).getValue());
else
valueStr = ""; //otherwise, set blank value
preferredFields.put(fiddef.getName(), valueStr);
}
}
}
return preferredFields;
}
...
//in your application at the method to process data(item events)
public void processEvent(Event event)
{
...
OMMItemEvent ie = (OMMItemEvent)event;
OMMMsg respMsg = ie.getMsg();
GenericOMMParser.parse(respMsg);
//If it is Refresh or Update data message, get data
if((respMsg.getMsgModelType() == RDMMsgTypes.MARKET_PRICE) &&
( respMsg.getMsgType() == OMMMsg.MsgType.REFRESH_RESP || respMsg.getMsgType() == OMMMsg.MsgType.UPDATE_RESP))
{
//Get CURRENCY, BID and ASK field
HashMap<String,String> preferredFields= GenericOMMParser.parseOMMData(respMsg.getPayload());
//Create JSON format
//{"CURRENCY": "JPY","BID":"108.87","ASK":"108.88"}
StringBuffer jsonDataFormatStrBuf = new StringBuffer("{");
if(preferredFields.containsKey("CURRENCY"))
jsonDataFormatStrBuf.append("\"CURRENCY\":\"" + preferredFields.get("CURRENCY")+"\",");
if(preferredFields.containsKey("BID"))
jsonDataFormatStrBuf.append("\"BID\":\""+ preferredFields.get("BID"));
if(preferredFields.containsKey("ASK"))
jsonDataFormatStrBuf.append("\",\"ASK\":\"" + preferredFields.get("ASK") + "\"}");
if (jsonDataFormatStrBuf.toString().length() > 1) //contain at least 1 field
System.out.println("Json Data format is " + jsonDataFormatStrBuf.toString());
}The example Refresh
message output:Msg Type: MsgType.REFRESH_RESP
…
Payload: 2060 bytes
FIELD_LIST
FIELD_ENTRY 1/PROD_PERM: 213
FIELD_ENTRY 2/RDNDISPLAY: 153
FIELD_ENTRY 3/DSPLY_NAME: BARCLAYS LON
FIELD_ENTRY 5/TIMACT: 09:34
FIELD_ENTRY 11/NETCHNG_1: 0.20
FIELD_ENTRY 12/HIGH_1: 109.26
FIELD_ENTRY 13/LOW_1: 108.80
FIELD_ENTRY 15/CURRENCY: JPY (392)
FIELD_ENTRY 17/ACTIV_DATE: 25 APR 2018
FIELD_ENTRY 19/OPEN_PRC: 108.80
FIELD_ENTRY 21/HST_CLOSE: 108.81
FIELD_ENTRY 22/BID: 109.01
FIELD_ENTRY 23/BID_1: 109.02
FIELD_ENTRY 24/BID_2: 109.02
FIELD_ENTRY 25/ASK: 109.04
FIELD_ENTRY 26/ASK_1: 109.04
FIELD_ENTRY 27/ASK_2: 109.04
…
Json Data format is {"CURRENCY":"JPY","BID":"109.01","ASK":"109.04"}The example Update
message output:Msg Type: MsgType.UPDATE_RESP
…
Payload: 212 bytes
FIELD_LIST
FIELD_ENTRY 22/BID: 109.02
FIELD_ENTRY 393/PRIMACT_1: 109.02
FIELD_ENTRY 25/ASK: 109.05
FIELD_ENTRY 275/SEC_ACT_1: 109.05
…
Json Data format is {"BID":"109.02","ASK":"109.05"}Note: an Update message
contains only change fields so CURRENCY may not in the Update message.If you would like to get
only your preference fields(CURRENCY, BID and ASK) from the server which is ADS(one
component of TREP), you can use Dynamic View feature which allows ADS sends
only fields specified in the request message to your application. For more
details and example application, please refer to How to request particular fields of an item (RIC) via RFA API0
Answers
-
there is an problem, if the Msg Type is UPDATE_RESP, I can't fetch the CURRENCY field at the same time .
Is there any way to ensure the CURRENCY field existed in every notice.
0 -
Hello @peng.xiaoliang
As far as I know there is no way. Hence, you need to keep CURRENCY received from the Refresh message e.g. set in it a class/instance 's variable.
Before creating a new JSON data format containing CURRENCY field
- get the CURRENCY kept in the class/instance's variable if the update message does not contain CURRENCY.
or
- update the class/instance's variable with the new CURRENCY received from the update message.
0 -
I think the latest TREP software supports JSON format, so you get the market data updates already in JSON. But I have not still tested it.
In that case you do not use RFA but another mechanism to connect to TREP, send requests and get JSON data.
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 689 Datastream
- 1.4K DSS
- 625 Eikon COM
- 5.2K Eikon Data APIs
- 11 Electronic Trading
- 1 Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 255 ETA
- 558 WebSocket API
- 39 FX Venues
- 15 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 277 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 23 RDMS
- 1.9K Refinitiv Data Platform
- 696 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 106 UPA
- 194 TREP Infrastructure
- 229 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 94 Workspace SDK
- 11 Element Framework
- 5 Grid
- 19 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛