When trying to publish value 0.00001 it is publishing as 0

nsharma
nsharma Newcomer
edited September 29 in EMA

Hello team,

I am using EMA ommConsumer where, when trying to publish value 0.00001 it is publishing as 0.

the code snippet I am using is as below:

nestedFieldList.add(EmaFactory.createFieldEntry().realFromDouble(25123, getBid(), 1));

Can anyone please help me out to understand the same.

Answers

  • Hello @nsharma

    Is the FID 25123 defined as REAL64?

    I tried publishing this value and able to see the desired result. PS: Its always better to use the enums like EXPONENT_NEG_13instead of 1.

     fieldList.add(EmaFactory.createFieldEntry().realFromDouble(21, 0.00001, 1));
    …
    

    and the result in the consumer -

    Service Name: DIRECT_FEED
    Item State: Open / Ok / None / 'Refresh Completed'
    DSPLY_NAME(3): abc
    CURRENCY(15): 840
    HST_CLOSE(21): 0.0000100000000
    .
    .
    

    You can also turn on the OMM logging in the SDK to see the raw messages being sent and received.

  • Hello @Gurpreet

    Thanks for the reply….

    FID 25123 is defined as Double.

    and yes, I have tried using the EXPONENT_NEG_13 previously it was rounding off the values due to which I tried 1 in that place and tried and it was working as expected but don't know how again it rounded off for 0.00001 to 0.

    Thanks!!!!!

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @nsharma

    Real and Double are distinct data types.

    If FID 25123 is defined as Double, you need to use EmaFactory.createFieldEntry().doubleValue​(int fieldId, double value) method instead.

  • Thanks @Jirapongse have done the changes as you mentioned will test and let you know the outcome.

    Hope it will not round-off the any values….

    Thanks again for the quick help!!!!!!

  • nsharma
    nsharma Newcomer
    edited September 30

    @Jirapongse I want to publish the value 0.000001 but not hard coded if I am storing it as double then double is rounding off to 0.0 is there any other method like doubleValue(int feildId, double arg) where we can store the 0.000001 in that variable and publish it to TREP?

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @nsharma

    Is it publishing (Interactive Provider or Non-Interactive Provider) or posting (OMM Consumer)?

  • Jirapongse
    Jirapongse ✭✭✭✭✭
    edited September 30

    @nsharma

    How did you define this 25123 field in a data dictionary file (RDMFieldDictionary)?

    According to this Publish Custom Data via Refinitiv Real-Time Distribution System by EMA article, you need to use the negative FIDs for your custom fields.

  • nsharma
    nsharma Newcomer
    edited September 30

    Hello @Jirapongse I have given as an example but the issue I am getting is in ASK, BID field with id 25, 22 respectively.

    Can you please let me know how I can publish 0.000001 other than doubleValue and realFromDouble methods as by storing in double variable it is rounding-off which I don't need.

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @nsharma

    You need to try this one by specifying a hint value.

    nestedFieldList.add(EmaFactory.createFieldEntry().realFromDouble(22, 0.000001, OmmReal.MagnitudeType.EXPONENT_NEG_6));
    
  • @Jirapongse This is hard coded but I don't want to do hardcode need to store in some variable and pass that variable.

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @nsharma

    I checked the code. If the hint is not specified, it will useOmmReal.MagnitudeType.EXPONENT_0.

    	public FieldEntry realFromDouble(int fieldId, double value)
    {
    return realFromDouble(fieldId, value, OmmReal.MagnitudeType.EXPONENT_0);
    }

    Due to the structure of REAL, the 0.00001 will be converted to long which is zero.

        boolean     _isBlank;

    int _hint;

    long _value;
  • Jirapongse
    Jirapongse ✭✭✭✭✭

    The structure of real requires long and hint.

  • How can I achieve this? @Jirapongse

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @nsharma
    Covert a double to a string and count the number of digits after a decimal point. Then, use the number of digits to calculate a hint. For example:

    import java.text.DecimalFormatSymbols;
    import java.text.DecimalFormat;
    public int countDecimalDigits(double number) {
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US);
    DecimalFormat df = new DecimalFormat("#.###############", symbols);
    String s = df.format(number);
    int decimalPointIndex = s.indexOf('.');

    if (decimalPointIndex == -1) {
    // No decimal point, so 0 digits after it
    return 0;
    } else {
    // Subtract 1 from the length to account for the decimal point itself
    return s.length() - decimalPointIndex - 1;
    }
    }




    nestedFieldList.add(EmaFactory.createFieldEntry().realFromDouble(22, 0.000001, 14-countDecimalDigits(0.000001)));
    nestedFieldList.add(EmaFactory.createFieldEntry().realFromDouble(25, 0.00001, 14-countDecimalDigits(0.00001)));
  • @Jirapongse again you have hardcoded value I need to pass the value into the variable not the hardcoded value

  • Jirapongse
    Jirapongse ✭✭✭✭✭
    double BidVal = 0.000001;
    double AskVal = 0.00001;

    nestedFieldList.add(EmaFactory.createFieldEntry().realFromDouble(22, BidVal, 14-countDecimalDigits(BidVal)));
    nestedFieldList.add(EmaFactory.createFieldEntry().realFromDouble(25, AskVal, 14-countDecimalDigits(AskVal)));