QuickFix / N how best to deal with multiple FIX versions

I am connecting to several APIs that use FXI4.2, but now I want to connect to another one that uses its own version of FIX4.4.

I have a router app that sends orders to various APIs and I feel like I need to duplicate all of my methods (e.g. OnMessage (), NewSingleOrder, etc.) in order to handle the two FIX protocols.

Is there a smarter way to do this to avoid this duplication?

Moderators: I know this is a little open right now, but I'll add some code snippets when I get some initial feedback.

public void OnMessage(QuickFix.FIX42.MarketDataIncrementalRefresh message, SessionID sessionID)
{
    int count = message.NoMDEntries.getValue();
    QuickFix.FIX42.MarketDataSnapshotFullRefresh.NoMDEntriesGroup repeatingMDItem = new QuickFix.FIX42.MarketDataSnapshotFullRefresh.NoMDEntriesGroup();

    DateTime sourceDT = DateTime.ParseExact(message.Header.GetField(52), "yyyyMMdd-HH:mm:ss.fff", ci);
    DateTime dt = TimeZoneInfo.ConvertTimeToUtc(sourceDT, utcZone);
    DateTime nowUTC = TimeZoneInfo.ConvertTime(DateTime.UtcNow, utcZone, utcZone);
    TimeSpan diffToUK = nowUTC - dt;

    for (int i = 1; i <= count; i++)
    {

        message.GetGroup(i, repeatingMDItem);

        String symbol = repeatingMDItem.GetField(55);

        int tickBandNoDecPlaces = int.Parse(repeatingMDItem.GetField(5071));
        masterForm.MDATA.AddData(symbol, tickBandNoDecPlaces, sourceDT);
    }
}

      

Q: will FIX44 accept all previous FIXs?

How can I make this agnostic about which version of the FIX?

        public void OnMessage(QuickFix.FIX42.MarketDataSnapshotFullRefresh message, SessionID sessionID)
        {
            OnMessageAgnostic(message, sessionID);
        }

        public void OnMessage(QuickFix.FIX44.MarketDataSnapshotFullRefresh message, SessionID sessionID)
        {
            OnMessageAgnostic(message, sessionID);
        }

        public int FixVersion(QuickFix.Message message)
        {
               switch (message.GetString(8)) // BeginString
                    {
                        case Values.BeginString_FIX42:
                            return 42;
                        case Values.BeginString_FIX44:
                            return 44;
                        default:
                            throw new NotSupportedException("This version of FIX is unsupported");
                    }
        }

        public void OnMessageAgnostic(QuickFix.Message message, SessionID sessionID)
        {

             int count;
             if (FixVersion(message)==44)
             {
                  count = ((QuickFix.FIX44.MarketDataSnapshotFullRefresh)message).NoMDEntries.getValue();
             }
        }

      

+3


source to share


1 answer


The problem is that FIX message types from different versions have no relationship other than the base class - at the lowest level, all FIX messages are received from Message

. You need to take the information you need from the post, package it in such a way that it is version-invalid (as much as possible), and then write the code with these version-independent structures.

I suggest that you allow the message cracker to do some initial filtering for you, if you're okay, to allow it to process, then pass the message to a handler that can handle that type of message:



public void OnMessage(QuickFix.FIX42.MarketDataIncrementalRefresh message, SessionID sessionID)
{
    this.marketDataIncrementalRefreshHandler.Handle(message);
}

public void OnMessage(QuickFix.FIX44.MarketDataIncrementalRefresh message, SessionID sessionID)
{
    this.marketDataIncrementalRefreshHandler.Handle(message);
}

... elsewhere ...

public interface FixMessageHandler
{
    void Handle(Message msg);
}

public class MarketDataIncrementalRefreshHandler : FixMessageHandler
{
    public void Handle(Message msg)
    {
        DateTime sourceDT = DateTime.ParseExact(message.Header.GetField(52), "yyyyMMdd-HH:mm:ss.fff", ci);
        DateTime dt = TimeZoneInfo.ConvertTimeToUtc(sourceDT, utcZone);
        DateTime nowUTC = TimeZoneInfo.ConvertTime(DateTime.UtcNow, utcZone, utcZone);
        TimeSpan diffToUK = nowUTC - dt;

        var noMDEntriesGroups = this.GetAllNoMDEntries(msg)
        foreach (var noMDEntriesGroup in noMDEntriesGroups)
        {
            masterForm.MDATA.AddData(
                noMDEntriesGroup.Symbol,
                noMDEntriesGroup.TickBandNoDecPlaces,
                sourceDT);
        }
    }

    private IEnumerable<NoMDEntriesGroup> GetAllNoMDEntries(Message msg)
    {
        switch (message.GetString(8)) // BeginString
        {
            case Values.BeginString_FIX42:
                return this.GetAllNoMDEntries((QuickFix.FIX42.MarketDataSnapshotFullRefresh)msg);
            case Values.BeginString_FIX44:
                return this.GetAllNoMDEntries((QuickFix.FIX44.MarketDataSnapshotFullRefresh)msg);
            default:
                throw new NotSupportedException("This version of FIX is unsupported");
        }
    }

    private IEnumerable<NoMDEntriesGroup> GetAllNoMDEntries(QuickFix.FIX42.MarketDataSnapshotFullRefresh msg)
    {
        int count = message.NoMDEntries.getValue();
        QuickFix.FIX42.MarketDataSnapshotFullRefresh.NoMDEntriesGroup repeatingMDItem = new QuickFix.FIX42.MarketDataSnapshotFullRefresh.NoMDEntriesGroup();
        for (int i = 1; i <= count; i++)
        {
            message.GetGroup(i, repeatingMDItem);

            yield return new NoMDEntriesGroup
            {
                Symbol = repeatingMDItem.GetField(55),
                TickBandNoDecPlaces = int.Parse(repeatingMDItem.GetField(5071)
            };
        }
    }

    private IEnumerable<NoMDEntriesGroup> GetAllNoMDEntries(QuickFix.FIX44.MarketDataSnapshotFullRefresh msg)
    {
        // Should be practically identical to the above version, with 4.4 subbed for 4.2
    }

    private class NoMDEntriesGroup
    {
        public string Symbol { get; set; }
        public int TickBandNoDecPlaces { get; set; }
    }
}

      

+3


source







All Articles