Package: simplefix
IntroductionFIX(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 ofQuickFIX.This package provides asimpleimplementation 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.LicenceThe module is licensed under theMIT 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.InstallationFor most users, the easiest and best way to install simplefix is usingpip:pipinstallsimplefixAll releases are uploaded to PyPI and available for installation, so you
can pin a known, tested version in your project’srequirements.txtorproject.toml(or whatever your build system uses). See thePyPI project pagefor the full
list of available versions.Source code releases are also available, together with some basic release
notes, from the project’sGitHub Releasespage.Basic UsageSee theProgrammer’s Guidefor
more information.Creating MessagesTo 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, usingappend_pair()is the easiest way to add a field to the message.
When adding aUTCTimestampvalue (ie, for tag 52) usingappend_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, callingencode()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 theencode()method that disables this functionality.  This is useful for
creating known-bad messages for testing purposes.Parsing MessagesTo extract FIX messages from a byte buffer, such as that received from a
socket, you should first create an instance of theFixParserclass.  For
each byte string received, append it to the internal reassembly buffer usingappend_buffer().  At any time, you can callget_message(): if there’s
no complete message in the parser’s internal buffer, it’ll return None,
otherwise, it’ll return aFixMessageinstance.Once you’ve received aFixMessagefromget_message(), you can: check
the number of fields withcount(), retrieve the value of a field usingget()or the built-in “[ ]” syntax, or iterate over all the fields using
“for … in …”.Members of repeating groups can be accessed usingget(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).ContributingComments, suggestions, bug reports, bug fixes – all contributions to
this project are welcomed.  See the project’sGitHubpage for access to the latest
source code, and please open anissuefor comments,
suggestions, and bugs.See the CONTRIBUTING.rst file for more detailed instructions.