source: proto/FIX/tests/fix_testgen.py @ 2317

Last change on this file since 2317 was 1316, checked in by cameron, 8 years ago

FIX tests

File size: 875 bytes
Line 
1#
2# FIX test file generator.
3# Robert D. Cameron   Aug. 18, 2011
4# (c)  All rights reserved.
5#
6
7SOH = "\x01"
8
9header1 = "8=FIX.4.4" +SOH
10header2 = "9=%s" + SOH
11
12def make_fix_msg_from_dict(msgdict):
13        msg_body = ""
14        for k in msgdict.keys():
15                msg_body += "%s=%s" % (k, msgdict[k]) + SOH
16        msg = header1 + (header2 % len(msg_body)) + msg_body
17        checksum = 0
18        for i in range(len(msg)): checksum += ord(msg[i])
19        checksum &= 0xFF
20        return msg + ("10=%03u" % checksum) + SOH
21
22t1 = {44: 'dummyforfield44'}
23
24def main():
25        msg1 = make_fix_msg_from_dict(t1)
26        f = file("msg1", "w")
27        f.write(msg1)
28        f.close()
29
30        f = file("errfile1", "w")
31        f.write("0" + msg1)
32        f.close()
33
34        f = file("errfile2", "w")
35        f.write(msg1[0:-1])
36        f.close()
37
38        f = file("errfile3", "w")
39        f.write(SOH + msg1)
40        f.close()
41
42        f = file("errfile4", "w")
43        f.write(msg1+SOH)
44        f.close()
45
46       
47
48if __name__ == "__main__":
49    main()
50
Note: See TracBrowser for help on using the repository browser.