Skip to content

Raw messages

A raw message reads the fields of any FIX message by tag, with no dictionary.

  • It converts values to integers, decimals, timestamps and the other FIX types.
  • It indexes the fields once and converts a value only when it is asked for.
  • It keeps every field in the order sent, including custom tags and duplicates.
Source Use
A log The log reader. Each record holds one.
Bytes that hold one message The tokenizer.
Bytes arriving from a connection The message stream.

The log reader is lenient. The tokenizer and the message stream are strict, and need SOH separators, a correct BodyLength and a correct CheckSum.

The examples read this order, shown as ReFIX prints it:

8=FIX.4.4|9=129|35=D|49=BUYSIDE|56=VENUE|34=3|52=20261103-09:30:36|11=ORDER-1|1=XXXXXXXX|55=ACME|54=1|60=20261103-09:30:36|40=2|44=101.25|38=100|10=021
message.get_str(11) # 'ORDER-1'
message.get_int(34) # 3
message.get_decimal(44) # Decimal('101.25')
message.get_utc_timestamp(60) # datetime(2026, 11, 3, 9, 30, 36, tzinfo=timezone.utc)
message.get(55) # b'ACME'
message.get_str(58) # None

A field that is absent reads as None. A value that cannot be converted raises InvalidValueError from refix.errors, which names the tag.

Each method returns the first field with the tag.

Method Python Rust
get bytes &[u8]
get_str str &str
get_int int i64
get_bool bool bool
get_decimal Decimal Decimal
get_utc_timestamp datetime UtcTimestamp
get_date date Date
get_time time Time
get_month_year MonthYear MonthYear

get_utc_timestamp_ns and get_time_ns return nanoseconds as an int, for values finer than datetime and time can hold.

for tag, value in message.entries():
print(tag, value)

Bytes that are not a field, such as text without an =, come under the tag refix.MALFORMED_TAG.

The fields come in the order sent, with duplicates. Printing a message gives its wire form, with | for SOH.

import refix
tokenizer = refix.Tokenizer()
message = tokenizer.tokenize(data)

tokenize raises a TokenizeError from refix.errors unless data holds exactly one valid message.

Bytes that end before the message does, bytes after the message and a failed check are all errors.

Feed the message stream the bytes as they arrive, in pieces of any size. It returns each complete message, and reports bytes that are not part of a message with the reason.

import refix
stream = refix.MessageStream()
def on_bytes(data: bytes) -> None:
stream.feed(data)
while (item := stream.next_message()) is not None:
if isinstance(item, refix.Garble):
print("skipped", len(item.bytes), "bytes:", item.reason.name)
else:
print(item.get_str(35))

next_message returns None when it needs more bytes.

The value of a data field can contain SOH, so it is read by the length in the field before it. The standard length fields are built in. Name any custom ones in a dialect:

dialect = refix.Dialect(extra_length_tags=[5001])
tokenizer = refix.Tokenizer(dialect)

MessageStream and read_log take a dialect in the same way.