question

Upvotes
Accepted
37 14 15 18

Parsing View Response Data

Hello, am having issues parsing trep api response data and would appreciate any help.

Currently, am using view and requesting data for ric "IBM.N". The requested fields are "ASK", and "BID". I would like to extract the BID and ASK data and put them into a map.

I would be grateful for a code snapshot of how to extracted these two fields into a map from the response data.

Regards

elektronrefinitiv-realtimetrepjava
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Monitored by @Pimchaya.Wongrukun

Hi @josa. Thank you for your participation in the forum.

Is the reply below satisfactory in resolving your query?

If so please can you click the 'Accept' text next to the appropriate reply. This will guide all community members who have a similar question.

Thanks

AHS

Upvotes
Accepted
9.6k 10 7 7

Hello @josa

RFA Java package provide the GenericOMMParser which is used to read and initialize dictionaries and parse any OMM message. Hence, you may modify GenericOMMParser to get your preference fields from the response and update the values in the map. The example source code is here:

 //create new method in GenericOMMParser.java to parse data and update map for BID and ASK field
    public static final void parseOMMData(OMMData data, HashMap<String,Double> fieldsMap)
    {
    	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) {
            		aValue=  fe.getData(fiddef.getOMMType());
            		if(!aValue.isBlank()) {
            			String key;
            			if(fe.getFieldId() ==22)
            				key = "BID";
            			else
            				key = "ASK";
            			fieldsMap.put(key, Double.parseDouble(aValue.toString()));
            		}
            			
            	}
            	
            }
        }
        
    }


//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.parseOMMData(respMsg.getPayload(),fieldsMap);
        System.out.println("In the map BID is " + fieldsMap.get("BID"));
        System.out.println("In the map ASK is " + fieldsMap.get("ASK"));
        ...
}
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Also: You may want to consider how you store values of type OMM Real (i.e. BID and ASK fields). Storing them in a Double is one choice (possible loss of precision!) and storing them in a BigDecimal (no loss of precision) is another choice. It all depends on your needs. Sometimes using Double (or double) as in the example above is 'good enough'. Anyway, you'll need to cast the aValue variable in the example to OMMNumeric. This will give you direct translation into double, BigDecimal and so on. No need to first convert to String and then to Double as in the example.

Upvotes
37 14 15 18

Thanks very much @Pimchaya.Wongrukun. Will try your code example and let you know if I need any more info.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.