Simple FIX Protocol Implementation

1.0.17 · active · verified Mon Apr 13

SimpleFIX is a Python library that provides a straightforward implementation of the FIX (Financial Information eXchange) application-layer protocol. It enables the creation, encoding, and decoding of FIX messages. Unlike full-fledged FIX engines, SimpleFIX focuses solely on message handling and does not include functionality for socket communication, session management, recovery, or message persistence. The library is actively maintained, with its latest version being 1.0.17.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a FIX 'New Order Single' message, append various standard fields including a UTC timestamp, encode it into bytes, and then parse it back using the `FixParser`. Standard FIX header tags like BeginString (8), MsgType (35), SenderCompID (49), and TargetCompID (56) are included, along with common order fields.

import simplefix
import datetime

# Create a FIX message
message = simplefix.FixMessage()
message.append_pair(8, "FIX.4.2") # BeginString
message.append_pair(35, "D")    # MsgType - New Order Single
message.append_pair(49, "SENDER") # SenderCompID
message.append_pair(56, "TARGET") # TargetCompID
message.append_pair(11, "ORDER123") # ClOrdID
message.append_pair(21, 1)      # HandlInst
message.append_pair(55, "IBM")   # Symbol
message.append_pair(54, 1)      # Side - Buy
message.append_pair(60, datetime.datetime.utcnow(), fix_type=simplefix.FIX_UTC_TIMESTAMP) # TransactTime
message.append_pair(38, 100)    # OrderQty
message.append_pair(40, 1)      # OrdType - Market

# Encode the message
encoded_message = message.encode()
print(f"Encoded Message: {encoded_message.decode('ascii').replace(chr(1), '|')}")

# Parse a FIX message
parser = simplefix.FixParser()
parser.append_buffer(encoded_message)

parsed_message = parser.get_message()

if parsed_message:
    print(f"Parsed MsgType: {parsed_message.get(35).decode('ascii')}")
    print(f"Parsed Symbol: {parsed_message.get(55).decode('ascii')}")
else:
    print("No complete message found in buffer.")

view raw JSON →