Skip to main content

Simple FIX Protocol implementation for Python

Project description

Build status Docs Code Health Coverage PyPI Python

Introduction

FIX (Financial Information eXchange) Protocol is a widely-used, text-based protocol for interaction between parties in financial trading. Banks, brokers, clearing firms, exchanges, and other general market participants use FIX protocol for all phases of electronic trading.

Typically, a FIX implementation exists as a FIX Engine: a standalone service that acts as a gateway for other applications (matching engines, trading algos, etc) and implements the FIX protocol. The most popular Open Source FIX engine is probably one of the versions of QuickFIX.

This package provides a simple implementation of the FIX application-layer protocol. It does no socket handling, and does not implement FIX recovery or any message persistence. It supports the creation, encoding, and decoding of FIX messages.

Licence

The module is licensed under the MIT license. While this is not legal advice, in short this means you’re free to do whatever you like with this code, with the exception of claiming you wrote it.

Basic Usage

Creating Messages

To create a FIX message, first create an instance of the FixMessage class.

msg = simplefix.FixMessage()

You can then add fields to the message as required. You should add the standard header tags 8, 34, 35, 49, 52, and 56 to all messages. For most tags, using append_pair() is the easiest way to add a field to the message. When adding a UTCTimestamp value (ie, for tag 52) using append_utc_timestamp() will take care of the formatting for you.

append_string() will decompose a “tag=value” string and add it as a proper field; append_strings() will do the same for a sequence of “tag=value” strings. append_data() will correctly append a data field, setting the length tag’s value, and putting the value tag after the length in the formatted message.

Once all fields are set, calling encode() will return a byte buffer containing the correctly formatted FIX message, with fields in the required order, and automatically added and set values for the BodyLength (9) and Checksum (10) fields.

Note that if you want to manually control the ordering of all fields, the value of the BodyLength or Checksum fields, there’s a ‘raw’ flag to the encode() method that disables this functionality. This is useful for creating known-bad messages for testing purposes.

Parsing Messages

To extract FIX messages from a byte buffer, such as that received from a socket, you should first create an instance of the FixParser class. For each byte string received, append it to the internal reassembly buffer using append_buffer() . At any time, you can call get_message() : if there’s no complete message in the parser’s internal buffer, it’ll return None, otherwise, it’ll return a FixMessage instance.

Once you’ve received a FixMessage from get_message() , you can: check the number of fields with count() , retrieve the value of a field using get() or the built-in “[ ]” syntax, or iterate over all the fields using “for … in …”.

Members of repeating groups can be accessed using get(tag, nth), where the “nth” value is an integer indicating which occurrence of the tag to return (note that the first occurrence is number one, not zero).

Contributing

Comments, suggestions, bug reports, bug fixes – all contributions to this project are welcomed. See the project’s GitHub page for access to the latest source code, and please open an issue for comments, suggestions, and bugs.

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

simplefix-1.0.7.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

simplefix-1.0.7-py2.py3-none-any.whl (19.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file simplefix-1.0.7.tar.gz.

File metadata

  • Download URL: simplefix-1.0.7.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for simplefix-1.0.7.tar.gz
Algorithm Hash digest
SHA256 d629fa5b458f4b184d74e2d91d2253d0a19e15ff279d506fa46b5630f424b840
MD5 08e4bbb0d08a4989087b4e48391128b9
BLAKE2b-256 216921412f74ecc67942c348d03bcae883de0e590a6684d2570875dc9b61f2ef

See more details on using hashes here.

File details

Details for the file simplefix-1.0.7-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for simplefix-1.0.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c4cf03c1c887fd432e297079b94b32f255296bdad4832f64644c403df15034d5
MD5 cb63b48545711d4bf8a9346ea3b9783b
BLAKE2b-256 72f3b0c7567f04c669dd10fbcef660da96195c12b61a15327ae2fc16808c21ae

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