2

I am new to FIX. I have a FIX message:

8=FIX.4.4|9=122|35=D|34=215|49=CLIENT12|52=20100225-19:41:57.316|56=B|1=Marcel|11=13346|21=1|40=2|44=5|54=1|59=0|60=20100225-19:39:52.020|10=072|

and I am using quickfixJ. Here is my class code:

    public String getYear(Message aMessage, SessionID aSessionID){
        try {
            crack(aMessage, aSessionID);
        } catch (Exception e) {
           e.printStackTrace();
        }

        String year = String.valueOf(mUTCCal.get(Calendar.YEAR));
        String begin = String.valueOf(BeginString);
        return year + " " + begin;
    }

and when I call this method I 2012 null I tried all sorts of methods for different fields and I get null. I am confused about why I do not get null for the date and how do I make it interpret correctly the other fields?

    quickfix.fix44.NewOrderSingle message;
    message = new quickfix.fix44.NewOrderSingle();
    SessionID session = new SessionID("beginString", "senderCompID", "targetCompID");
    MyApp app = new MyApp("", "", "");
    String result = app.myMessage(message, session);
    System.out.println(result);

I do not understand where to input the string I have (up top) into message

    public void onMessage(Message message, SessionID sessionID) throws FieldNotFound {
        Header header = message.getHeader();
        String FIX = header.getString(8);

        System.out.println(FIX);
    }

    public void onMessage(quickfix.fix44.NewOrderSingle message, SessionID sessionID) throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue {
    Header header = message.getHeader();
    String FIX = header.getString(8);
            String a = message.getString(1);

            System.out.println(a);
            System.out.println(FIX);}
jon
  • 253
  • 4
  • 8
  • 16

1 Answers1

2

In order to correctly get and parse FIX messages via QuickFIX, you must:

The FromApp method can be very simple:

public void fromApp(Message message, SessionID sessionID)
{
  crack(message, sessionID);
}

Now, in your example you have a message FIX 4.4 of type 35=D [NewOrderSingle]

Therefore, you MUST implement a method as follows:

    public override void onMessage(QuickFix44.NewOrderSingle message, SessionID session)
    {
        base.onMessage(message, session);
    }

Now into your method you can easily work with all the fields you need:

    public override void onMessage(QuickFix44.NewOrderSingle message, SessionID session)
    {
        base.onMessage(message, session);

        ClOrdID ordid = new ClOrdID();
        message.get(ordid);
    }

Please also take a look here: http://www.quickfixengine.org/quickfix/doc/html/receiving_messages.html

stexcec
  • 1,143
  • 1
  • 18
  • 34
  • Thank you very much! Your response helped very much. This worked. I read the receiving messages page and I understand now about the FIX version and message type. Thanks. Do you have a simple example of code in main that would print ordid? – jon Nov 13 '12 at 17:55
  • Once you have the ordid in the onMessage method, you can store it in a class variable or consume it in the same method. – stexcec Nov 13 '12 at 18:36
  • I do not understand the override method. Is the quickfix.fix44.NewOrderSingle message the same message as from the fromApp method? I am looking here http://www.quickfixj.org/quickfixj/usermanual/1.5.1/usage/receiving_messages.html . quickfix.fix44.NewOrdersingle objects do not take any input, so how do I create a this object with my string as the input? Is there documentation on this ovveriding method? The only thing i saw is "Any function you do not overload will by default throw an UnsupportedMessageType exception" – jon Nov 13 '12 at 19:43
  • onMessage() is for handling **received** messages, not sent messages. The crack() method in fromApp() will take that original message, cast it to the correct type, and call the appropriate onMessage() override; if there is no approprate override, then it throws the exception. If you want to create and send a NewOrderSingle, see [these docs](http://quickfixj.org/quickfixj/usermanual/1.5.1/usage/sending_messages.html). – Grant Birchmeier Nov 13 '12 at 21:21
  • For some reason my handler onMessage(quickfix.fix44.NewOrderSingle message, SessionID session) is being skipped over. I am not getting any errors. The app recognizes it as a handler but when I run after it runs crack(message, session) it terminates and does not go to the handler. Do you know what could be the cause? I tried also implementing using @Handler but it did not help – jon Nov 21 '12 at 21:43
  • @jon: It's very strange. You wrote that you had asuccess implementing the crack on November 13. what have you changed? PLase try to implement another handler for a different FIX message, and let me know. – stexcec Nov 22 '12 at 08:30
  • I never implemented a a handler for receiving messages using QuickFix44.NewOrderSingle message as input arg, only Message message. I posted my code at top. The first onMessage method works, the second does not, it seems, is skipped over. I have tried also with Fix 4.2 messages and have not had success. – jon Nov 23 '12 at 14:23
  • I get this error when I try message.getField(1); in onMessage( Message message... The method getField(int) from the type FieldMap is not visible – jon Nov 23 '12 at 15:09
  • Hi @jon: you must implement an handler for every kind of message you want to use. PLease, try to implement an handler for the specific messageType. When the handler is triggered, you have the correct FIX message and you can start working with it. AVOID to use the method getField(), instead use the suggested method that you can find in the documentation. – stexcec Nov 27 '12 at 10:15
  • Hi @stexcec: I would like to implement a handler for the specific messageType and FIX version, but my handlers are not being called by the reflection of crack method. No action is taken. And aside from that, in the documentation quickfix suggests creating an object like Account account = new Account(); message.get(account); can you call toString(message.get(account)); ? – jon Dec 06 '12 at 16:04