FIX Message

Please refer to the section Message description for more information about FIX Message.

Creating FIX message

FIX Message object can be created in two different ways:

  • Create FIX message skeleton using FIX message factory and populate fields

  • Create FIX message from the raw FIX message (byte array)

To create a skeleton for a FIX application-level message, use the V12.FIXAntenna.FixMessage.__init__() method. Then set all required field for the newly created FIX message object.

For example:

from module import FIXFields, FIXAntenna as v12

engine = v12.FixEngine()

msg = v12.FixMessage("A", "FIX44")
msg.set(FIXFields.ClOrdID, "90001008");
msg.set(FIXFields.Side, "1");
msg.set(FIXFields.TimeInForce, "0");

Use the V12.FIXAntenna.FixMessage.from_string() static method to parse a string containing a raw FIX message into the FIXMessage class.

For example:

from module import FIXFields, FIXAntenna as v12

engine = v12.FixEngine()

msg = v12.FixMessage.from_string("8=FIX.4.49=5235=249=SC56=FE34=252=20090126-10:59:427=116=110=174", "FIX44")

Get field

Use the V12.FIXAntenna.FixMessage.get() method to get the FIX field value.

This method retrieves the field value by tag number and returns a string representation of the value. The field can be:

  • Not defined for this message type by specification.

  • Defined as optional for this message type by specification and absent in this message instance.

  • Defined for this message type by specification and present in this message instance.

In the 1st case the method throws exception. In the 2nd case the method returns “”. In the 3rd case the method returns the value.

Set field

Use the V12.FIXAntenna.FixMessage.set() method to set a field value.

This method returns “true” if the given tag is found and the old value is replaced with the new one. Otherwise the method returns “false” (the given tag is inserted).

The method throws exception if it cannot be executed (e.g. the given tag is not defined for this message type).

Remove field

Use the V12.FIXAntenna.FixMessage.remove() method to remove a field by tag.

This method returns “true” if the given tag is found and the field is removed. Otherwise the method returns “false”.

Repeating group

Please refer to the section Repeating Groups description for more information about repeating groups.

The V12.FIXAntenna.FixGroup class is designed to work with Repeating Groups. The access to the repeating groups is provided by the V12.FIXAntenna.FixMessage class. The common workflow when working with repeating groups is

  • get pointer to the instance of the repeating group from the FIX message

  • get/set fields inside the repeating groups specifying field, value and entry index

  • release pointer to the repeating group

In case of nested repeating groups the parent repeating group should be used to get pointer to the inner repeating group the same way it is done in FIX message. In theory the level of nesting is not limited by the FIX protocol standard.

To add repeating group to the message simply set value for the repeating group leading tag to the number of entries planned for the repeating group.

To resize repeating group simply modify the value of leading tag. When setting the new value for the leading tag, the group is re-created and old field values inside the group are erased.

The V12.FIXAntenna.FixGroup class contains methods to work with message fields, similar to those existing in the V12.FIXAntenna.FixMessage class, however in contrast to them, there is an additional argument defining index (a sequence number starting with 0) of the group entry.

Use the V12.FIXAntenna.FixMessage.remove() method, where tag is a Repeating Group Leading Tag, to remove the Repeating Group. Setting the corresponding tag to zero is not allowed (Parser Exception is thrown).

If non-existing or invalid values are specified for the arguments in the methods above then exception is thrown.

Example below demonstrates how to work with repeating group.

msg = v12.FixMessage("i", "FIX44")
# create a new group with 2 entries
msg[FIXFields.NoQuoteSets] = "2"
group = msg.get_group(FIXFields.NoQuoteSets)
# set value for the field in 1st and 2nd entries
group[0][FIXFields.QuoteSetID] = "a"
group[0][FIXFields.TotNoQuoteEntries] = "100"
group[1][FIXFields.QuoteSetID] = "b"
group[1][FIXFields.TotNoQuoteEntries] = "200"
# create nested repeating group for the entry at index 0 with size 1
group[0][FIXFields.NoQuoteEntries] = "1"
# get nested repeating group
nested_group = group[0].get_group(FIXFields.NoQuoteEntries)
# set value for nested group field
nested_group[0][FIXFields.QuoteEntryID] = "aa"

User defined fields

User Defined Fields (the tag numbers 5000 to 9999) are operated the same way as standard fields.

Copy message

To copy FIX message, use the V12.FIXAntenna.FixMessage.__init__() method. For example:

msg = v12.FixMessage("i", "FIX44")
msg2 = v12.FixMessage(msg)