Skip to content

Commit

Permalink
Update doc for new parsing options.
Browse files Browse the repository at this point in the history
  • Loading branch information
da4089 committed Feb 17, 2022
1 parent b8e638b commit a111a65
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 23 deletions.
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'SimpleFIX.tex', u'SimpleFIX Documentation',
(master_doc, 'SimpleFIX.tex', u'SimpleFIX Programmer\'s Guide',
u'David Arnold', 'manual'),
]

Expand All @@ -158,7 +158,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'simplefix', u'SimpleFIX Documentation',
(master_doc, 'simplefix', u'Programmer\'s Guide',
[author], 1)
]

Expand Down
51 changes: 44 additions & 7 deletions doc/creating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ Creating Messages

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


.. index:: FixMessage
.. code-block:: python
:linenos:
messsage = simplefix.FixMessage()
.. index:: header

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, unless
Expand All @@ -17,10 +19,13 @@ you're deliberately creating a malformed message for testing or similar.
Simple Fields
.............

.. index:: append_pair

For most tags, using ``append_pair()`` is the easiest way to add a field
to the message.

.. code-block:: python
:linenos:
message.append_pair(1, "MC435967")
message.append_pair(54, 1)
Expand All @@ -29,16 +34,20 @@ to the message.
Note that any type of value can be used: it will be explicitly converted
to a string before encoding the message.

.. index:: BeginString, BodyLength, MsgType, Checksum

With a few exceptions, the message retains the order in which fields are
added. The exceptions are that fields BeginString (8), Length (9),
added. The exceptions are that fields BeginString (8), BodyLength (9),
MsgType (35), and Checksum (10) are encoded in their required locations,
regardless of what order they were added to the Message.

Header Fields
.............

The Message class does not distinguish header fields from body fields,
with one exception.
The ``FixMessage`` class does not distinguish header fields from body
fields, with one exception.

.. index:: append_pair, header

To enable fields to be added to the FIX header after body fields have
already been added, there's an optional keyword parameter to the
Expand All @@ -47,10 +56,13 @@ already been added, there's an optional keyword parameter to the
any previously added header fields, starting at the beginning of the
message.

.. index:: MsgSeqNum, SendingTime

This is normally used for setting things like MsgSeqNum (34) and
SendingTime (52) immediately prior to encoding and sending the message.

.. code-block:: python
:linenos:
message.append_pair(8, "FIX.4.4")
message.append_pair(35, 0)
Expand All @@ -65,19 +77,24 @@ the message. After encoding, the order of fields would be: 8, 9, 35,
34, 52, 49, 56, 112, 10.

It's not necessary, but field 49 and 56 could also be written with
``header`` set ``True``, in which case, they'd precede 34 ane 52 when
``header`` set ``True``, in which case, they'd precede 34 and 52 when
encoded.

See ``append_time()`` below for details of that method.
.. index:: append_utc_timestamp

See ``append_utc_timestamp()`` below for details of that method.

Pre-composed Pairs
..................

.. index:: append_string, append_strings

In some cases, your FIX application might have the message content
as pre-composed "tag=value" strings. In this case, as an optimisation,
the ``append_string()`` or ``append_strings()`` methods can be used.

.. code-block:: python
:linenos:
BEGIN_STRING = "8=FIX.4.2"
STR_SEQ = ["49=SENDER", "56=TARGET"]
Expand All @@ -92,31 +109,42 @@ body fields.
Timestamps
..........

.. index:: UTCTimestamp, UTCTimeOnly, TZTimestamp, TZTimeOnly

The FIX protocol defines four time types: UTCTimestamp, UTCTimeOnly,
TZTimestamp, and TZTimeOnly. Field values of these types can be added
using dedicated functions, avoiding the need to translate and format
time values in the application code.

.. index:: append_utc_timestamp, append_tz_timestamp
.. index:: append_utc_time_only, append_tz_time_only
.. code-block:: python
:linenos:
message.append_utc_timestamp(52, precision=6, header=True)
message.append_tz_timestamp(1132, my_datetime)
message.append_utc_time_only(1495, start_time)
message.append_tz_time_only(1079, maturity_time)
.. index:: time, datetime

The first parameter to these functions is the field's tag number. The
second parameter is optional: if None or not supplied, it defaults to the
current time, otherwise it must be a Unix epoch time (like from
``time.time()``), or a ``datetime`` instance.

.. index:: precision, second, milliseconds, microseconds, header

There are two keyword parameters: ``precision`` which can be 0 for just
seconds, 3 for milliseconds, or 6 for microseconds; and ``header`` to
insert this field in the header rather than the body.

In addition, there are a set of methods for creating correctly formatted
time only values from their components:

.. index:: append_utc_time_only_parts, append_tz_time_only_parts
.. code-block:: python
:linenos:
message.append_utc_time_only_parts(1495, 7, 0, 0, 0, 0)
message.append_tz_time_only_parts(1079, 20, 0, 0, offset=-300)
Expand All @@ -125,6 +153,8 @@ As usual, the first parameter to these functions is the field's tag number.
The next three parameters are the hour, minute, and seconds of the time value,
followed by optional milliseconds and microseconds values.

.. index:: timezone

The timezone for the TZTimeOnly field is set using an offset value, the
number of minutes east of UTC. Thus CET will be offset 60 minutes, and
New York offset -240 minutes (four hours west).
Expand All @@ -136,7 +166,9 @@ to manage the formatting itself.
Repeating Groups
................

There is no specific support for creating repeating groups in Messages.
.. index:: repeating group

There is no specific support for creating repeating groups in FixMessages.
The count field must be appended first, followed by the group's member's
fields.

Expand All @@ -146,15 +178,20 @@ but note that the count fields are not added automatically.
Data Fields
...........

.. index:: data, raw data

There are numerous defined fields in the FIX protocol that use the *data*
type. These fields consist of two parts: a length, which must come first,
immediately followed by the value field, whose value may include the ASCII
SOH character, the ASCII NUL character, and in fact any 8-bit byte value.

.. index:: append_data

To append a data field to a message, the ``append_data()`` method can be
used. It will correctly add both the length field and the value field.

.. code-block:: python
:linenos:
message.append_data(95, 96, "RAW DATA \x00\x01 VALUE")
Expand Down
4 changes: 2 additions & 2 deletions doc/getting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Installation
============

simplefix has a few dependencies. Firstly, it is known to run on
Python_ 2.6, 2.7, 3.3, 3.4, 3.5, 3.6, and 3.7. It will not run on
Python 2.5 or earlier.
Python_ 3.3 through to 3.10. It will not run on Python 2.7 or
earlier versions.

You can install it using pip_::

Expand Down
3 changes: 3 additions & 0 deletions doc/import.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Importing
You can import the *simplefix* module maintaining its internal structure,
or you can import some or all bindings directly.

.. index:: simplefix, FixMessage
.. code-block:: python
:linenos:
Expand All @@ -22,6 +23,8 @@ Or
message = FixMessage()
.. index:: import, namespace

Note that the "import \*" form is explicitly supported, with the exposed
namespace explicitly managed to contain only the public features of the
package.
Expand Down
7 changes: 0 additions & 7 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,3 @@ SimpleFIX
creating
encoding
parsing

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
Loading

0 comments on commit a111a65

Please sign in to comment.