@@ -4,11 +4,13 @@ Creating Messages
44
55To create a FIX message, first create an instance of the FixMessage class.
66
7-
7+ .. index :: FixMessage
88.. code-block :: python
9+ :linenos:
910
1011 messsage = simplefix.FixMessage()
1112
13+ .. index :: header
1214
1315You can then add fields to the message as required. You should add the
1416standard header tags 8, 34, 35, 49, 52, and 56 to all messages, unless
@@ -17,10 +19,13 @@ you're deliberately creating a malformed message for testing or similar.
1719Simple Fields
1820.............
1921
22+ .. index :: append_pair
23+
2024For most tags, using ``append_pair() `` is the easiest way to add a field
2125to the message.
2226
2327.. code-block :: python
28+ :linenos:
2429
2530 message.append_pair(1 , " MC435967" )
2631 message.append_pair(54 , 1 )
@@ -29,16 +34,20 @@ to the message.
2934 Note that any type of value can be used: it will be explicitly converted
3035to a string before encoding the message.
3136
37+ .. index :: BeginString, BodyLength, MsgType, Checksum
38+
3239With a few exceptions, the message retains the order in which fields are
33- added. The exceptions are that fields BeginString (8), Length (9),
40+ added. The exceptions are that fields BeginString (8), BodyLength (9),
3441MsgType (35), and Checksum (10) are encoded in their required locations,
3542regardless of what order they were added to the Message.
3643
3744Header Fields
3845.............
3946
40- The Message class does not distinguish header fields from body fields,
41- with one exception.
47+ The ``FixMessage `` class does not distinguish header fields from body
48+ fields, with one exception.
49+
50+ .. index :: append_pair, header
4251
4352To enable fields to be added to the FIX header after body fields have
4453already been added, there's an optional keyword parameter to the
@@ -47,10 +56,13 @@ already been added, there's an optional keyword parameter to the
4756any previously added header fields, starting at the beginning of the
4857message.
4958
59+ .. index :: MsgSeqNum, SendingTime
60+
5061This is normally used for setting things like MsgSeqNum (34) and
5162SendingTime (52) immediately prior to encoding and sending the message.
5263
5364.. code-block :: python
65+ :linenos:
5466
5567 message.append_pair(8 , " FIX.4.4" )
5668 message.append_pair(35 , 0 )
@@ -65,19 +77,24 @@ the message. After encoding, the order of fields would be: 8, 9, 35,
657734, 52, 49, 56, 112, 10.
6678
6779It's not necessary, but field 49 and 56 could also be written with
68- ``header `` set ``True ``, in which case, they'd precede 34 ane 52 when
80+ ``header `` set ``True ``, in which case, they'd precede 34 and 52 when
6981encoded.
7082
71- See ``append_time() `` below for details of that method.
83+ .. index :: append_utc_timestamp
84+
85+ See ``append_utc_timestamp() `` below for details of that method.
7286
7387Pre-composed Pairs
7488..................
7589
90+ .. index :: append_string, append_strings
91+
7692In some cases, your FIX application might have the message content
7793as pre-composed "tag=value" strings. In this case, as an optimisation,
7894the ``append_string() `` or ``append_strings() `` methods can be used.
7995
8096.. code-block :: python
97+ :linenos:
8198
8299 BEGIN_STRING = " 8=FIX.4.2"
83100 STR_SEQ = [" 49=SENDER" , " 56=TARGET" ]
@@ -92,31 +109,42 @@ body fields.
92109Timestamps
93110..........
94111
112+ .. index :: UTCTimestamp, UTCTimeOnly, TZTimestamp, TZTimeOnly
113+
95114The FIX protocol defines four time types: UTCTimestamp, UTCTimeOnly,
96115TZTimestamp, and TZTimeOnly. Field values of these types can be added
97116using dedicated functions, avoiding the need to translate and format
98117time values in the application code.
99118
119+ .. index :: append_utc_timestamp, append_tz_timestamp
120+ .. index :: append_utc_time_only, append_tz_time_only
100121.. code-block :: python
122+ :linenos:
101123
102124 message.append_utc_timestamp(52 , precision = 6 , header = True )
103125 message.append_tz_timestamp(1132 , my_datetime)
104126 message.append_utc_time_only(1495 , start_time)
105127 message.append_tz_time_only(1079 , maturity_time)
106128
129+ .. index :: time, datetime
130+
107131The first parameter to these functions is the field's tag number. The
108132second parameter is optional: if None or not supplied, it defaults to the
109133current time, otherwise it must be a Unix epoch time (like from
110134``time.time() ``), or a ``datetime `` instance.
111135
136+ .. index :: precision, second, milliseconds, microseconds, header
137+
112138There are two keyword parameters: ``precision `` which can be 0 for just
113139seconds, 3 for milliseconds, or 6 for microseconds; and ``header `` to
114140insert this field in the header rather than the body.
115141
116142In addition, there are a set of methods for creating correctly formatted
117143time only values from their components:
118144
145+ .. index :: append_utc_time_only_parts, append_tz_time_only_parts
119146.. code-block :: python
147+ :linenos:
120148
121149 message.append_utc_time_only_parts(1495 , 7 , 0 , 0 , 0 , 0 )
122150 message.append_tz_time_only_parts(1079 , 20 , 0 , 0 , offset = - 300 )
@@ -125,6 +153,8 @@ As usual, the first parameter to these functions is the field's tag number.
125153The next three parameters are the hour, minute, and seconds of the time value,
126154followed by optional milliseconds and microseconds values.
127155
156+ .. index :: timezone
157+
128158The timezone for the TZTimeOnly field is set using an offset value, the
129159number of minutes east of UTC. Thus CET will be offset 60 minutes, and
130160New York offset -240 minutes (four hours west).
@@ -136,7 +166,9 @@ to manage the formatting itself.
136166Repeating Groups
137167................
138168
139- There is no specific support for creating repeating groups in Messages.
169+ .. index :: repeating group
170+
171+ There is no specific support for creating repeating groups in FixMessages.
140172The count field must be appended first, followed by the group's member's
141173fields.
142174
@@ -146,15 +178,20 @@ but note that the count fields are not added automatically.
146178Data Fields
147179...........
148180
181+ .. index :: data, raw data
182+
149183There are numerous defined fields in the FIX protocol that use the *data *
150184type. These fields consist of two parts: a length, which must come first,
151185immediately followed by the value field, whose value may include the ASCII
152186SOH character, the ASCII NUL character, and in fact any 8-bit byte value.
153187
188+ .. index :: append_data
189+
154190To append a data field to a message, the ``append_data() `` method can be
155191used. It will correctly add both the length field and the value field.
156192
157193.. code-block :: python
194+ :linenos:
158195
159196 message.append_data(95 , 96 , " RAW DATA \x00\x01 VALUE" )
160197
0 commit comments