quickfix-j / quickfixj

QuickFIX/J is a full featured messaging engine for the FIX protocol. - This is the official project repository.
http://www.quickfixj.org
Other
934 stars 607 forks source link

Generated messages should return header from their fix version #801

Open Svanar opened 2 months ago

Svanar commented 2 months ago

Is your feature request related to a problem? Please describe. Generated messages should have overridden getHeader() method to return header that corresponds to used protocol version.

Describe the solution you'd like In order to set header fields I would like to have returned header that if specific to fix version that message comes from. I presented that with code example in additional context.

What I think would be nice is to make method getHeader return quickfix.fix44.Message.Header so building messages can be done without any casting, making it more fluent. What is more changing behavior to one I described would make it easier to work with for new devs, because IDE would hint available methods.

Describe alternatives you've considered Casting quickfix.Message.Header to actual header, for example quickfix.fix44.Message.Header

Additional context Example code pattern that I currently use, but it is a bit tedious to write it each time I add fields in header.

import quickfix.Message;
import quickfix.field.TargetSubID;
import quickfix.fix44.QuoteRequest;

class Main {

    public static void main(String[] args) {
        QuoteRequest quoteRequest = new QuoteRequest();

        Message.Header header = quoteRequest.getHeader();
        // header.set(new TargetSubID("subId")); // Does not work

        // casting is needed
        quickfix.fix44.Message.Header fix44Header = (quickfix.fix44.Message.Header) header;
        fix44Header.set(new TargetSubID("subId"));

    }

}
chrjohn commented 2 months ago

Thanks for opening this issue.

If you're not tied to using the type safe methods you could also use e.g.:

https://github.com/quickfix-j/quickfixj/blob/3366b36fdd65ec5af83d33e4a8335db4ffdcff2b/quickfixj-base/src/main/java/quickfix/FieldMap.java#L157

Svanar commented 2 months ago

That was one of my attempts and while it is working I think that having it type safe makes it great and generated classes are really good with that hence my idea.