Skip to main content

A parser for FIX messages

Project description

jetblack-fixparser

A parser for FIX messages.

Installation

The package can be installed with pip.

pip install jetblack-fixparser

Protocol Files

While FIX is a standard, the structure of the fields and messages is configurable. This configuration is typically loaded from a file. The source repository contains a number of such files in the /etc folder in YAML format. There is also a QuickFix loader.

The YAML format makes use of defaults. All message fields default to type field, so only group and component fields need to be explicitly specified. Also all message fields are consider optional, non-optional fields must be marked as required: true.

Usage

Decoding

To decode a FIX bytes buffer -

from jetblack_fixparser import load_yaml_protocol, FixMessage

buffer = b'8=FIX.4.4|9=94|35=3|49=A|56=AB|128=B1|34=214|50=U1|52=20100304-09:42:23.130|45=176|371=15|372=X|373=1|58=txt|10=058|',

protocol = load_yaml_protocol(
    'FIX44.yaml',
    is_millisecond_time=True,
    is_float_decimal=True
)

fix_message = FixMessage.decode(
    protocol,
    buffer,
    sep=b'|',
    strict=True,
    validate=True,
    convert_sep_for_checksum=True
)

print(fix_message.message)

Note that strict validation is enabled. This ensures all required fields are specified. Also the separator is changed from NULL to | to so they can be displayed. However the checksum was calculated with the original field separator so the convert_sep_for_checksum is set to true.

Encoding

To encode a dictionary describing a FIX message -

from datetime import datetime, timezone
from jetblack_fixparser import load_yaml_protocol, FixMessage

protocol = load_yaml_protocol(
    'FIX44.yaml',
    is_millisecond_time=True,
    is_float_decimal=True,
    is_type_enum=None
)
sending_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=timezone.utc)

fix_message = FixMessage(
    protocol,
    {
        'MsgType': 'LOGON',
        'MsgSeqNum': 42,
        'SenderCompID': "SENDER",
        'TargetCompID': "TARGET",
        'SendingTime': sending_time,
        'EncryptMethod': "NONE",
        'HeartBtInt': 30
    }
)
buffer = fix_message.encode(regenerate_integrity=True)

print(buffer)

Note that the BeginString, BodyLength and Checksum fields were automatically generated.

Factories

To encode and decode a message using a factory -

from datetime import datetime, timezone
from jetblack_fixparser import load_yaml_protocol, FixMessage, FixMessageFactory

protocol = load_yaml_protocol(
    'FIX44.yaml',
    is_millisecond_time=True,
    is_float_decimal=True,
    is_type_enum=None
)

factory = FixMessageFactory(protocol, "SENDER", "TARGET")

sending_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=timezone.utc)
fix_messages = factory.create(
        'LOGON',
        42,
        sending_time,
        {
            'EncryptMethod': "NONE",
            'HeartBtInt': 30
        }
    )

buffer = fix_message.encode(regenerate_integrity=True)
roundtrip = FixMessage.decode(protocol, buffer)
assert fix_message.message == roundtrip.message

Because the sender and target remain the same, we can simplify message generation with the factory.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jetblack-fixparser-2.2.0.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

jetblack_fixparser-2.2.0-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

Details for the file jetblack-fixparser-2.2.0.tar.gz.

File metadata

  • Download URL: jetblack-fixparser-2.2.0.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.1 CPython/3.8.5 Linux/5.8.0-34-generic

File hashes

Hashes for jetblack-fixparser-2.2.0.tar.gz
Algorithm Hash digest
SHA256 2b6dda40d214115bf01d93d75e85c6613bb9a9b97b4c4772f51e243fb2efebc3
MD5 2f2a4faf55ab08a07039c80bf3aed930
BLAKE2b-256 9d5e051eb89da195671911357caf5b3c61b8ee507cd59b71bc24ed5badbec842

See more details on using hashes here.

File details

Details for the file jetblack_fixparser-2.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jetblack_fixparser-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08f40e21e6c697170c3eaee95fa1eb3a591112e54cdd1b963bd0478206f69298
MD5 787fa585bb1a8280536c1b1ce0ec30a1
BLAKE2b-256 9a1b0689e7f59a5959bafe58483e68434a5023cf035f26bac30694ecc13f818b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page