Esempio n. 1
0
    def test_message_bad_binary_length(self):
        """ Test for message with missing binary data """
        parser = FIXParser(self.receiver,
                           header_fields=[8, 9],
                           binary_fields=[1000],
                           max_length=100)

        # length too short
        with self.assertRaises(FIXParserError):
            parser.on_data_received(to_fix('8=FIX.4.2',
                                           '9=32',
                                           '42=A',
                                           '1000=2',
                                           '1001=abababababab',
                                           '10=000'))

        # length too long
        # This will not raise an error
        parser.on_data_received(to_fix('8=FIX.4.2',
                                       '9=32',
                                       '42=A',
                                       '1000=20',
                                       '1001=ab',
                                       '10=000'))
        self.assertEquals(0, self.receiver.count)
        self.assertTrue(parser.is_parsing)
Esempio n. 2
0
    def test_bad_binary_fields(self):
        """ Test bad binary fields """
        parser = FIXParser(self.receiver,
                           binary_fields=[1000],
                           header_fields=[8, 9])

        # Missing binary value portion of binary field
        # BUGBUG: This can cause some problems, because the parser
        # does not attempt to validate until the entire
        # field has been read in.  Which this will fail because
        # the length goes past the end of the message.
        # For now, live with this.
        with self.assertRaises(FIXParserError):
            parser.on_data_received(to_fix('8=FIX.4.2',
                                           '9=32',
                                           '1000=5',
                                           '999=11',
                                           '10=001'))

        # Missing binary length portion (the only time this
        # really impacts something is if the field has an
        # embedded \x01).
        with self.assertRaises(FIXParserError):
            parser.on_data_received(to_fix('8=FIX.4.2',
                                           '9=32',
                                           '1001=1010\x011010',
                                           '10=001'))

        parser.on_data_received(to_fix('8=FIX.4.2',
                                       '9=14',
                                       '1001=10101010',
                                       '10=127'))
        self.assertIsNone(self.receiver.last_error)
        self.assertEquals(1, self.receiver.count)
        self.assertIsNotNone(self.receiver.last_received_message)
Esempio n. 3
0
    def test_partial_binary_data(self):
        """ Receive a piece of binary data split into two parts """
        parser = FIXParser(self.receiver,
                           binary_fields=[99],
                           header_fields=[8, 9])

        text = to_fix('8=FIX.4.2',
                      '9=38',
                      '35=A') + '99=5\x01100=12'
        text2 = to_fix('345',
                       '919=this',
                       '955=that',
                       '10=198')
        parser.on_data_received(text)
        self.assertTrue(parser.is_parsing)

        parser.on_data_received(text2)
        self.assertFalse(parser.is_parsing)

        self.assertEquals(1, self.receiver.count)

        message = self.receiver.last_received_message
        self.assertIsNotNone(message)
        self.assertEquals(8, len(message))
        self.assertTrue(message.verify(fields=[(8, 'FIX.4.2'),
                                               (9, '38'),
                                               (35, 'A'),
                                               (99, '5'),
                                               (100, '12345'),
                                               (919, 'this'),
                                               (955, 'that'),
                                               (10, '198')]))
Esempio n. 4
0
 def test_nested_group_from_list(self):
     """ Call to_binary() on a nested grouped message from a list """
     # As its difficult to test this, convert the (unordered)
     # dict into an OrderedDict() before inserting (sorting by tag).
     # This makes it easier to do the comparison.
     mess = FIXMessage(header_fields=[8, 9],
                       source=to_ordered_dict([(8, 'FIX.4.2'),
                                               (100, [{
                                                   101: 'abc',
                                                   102: 'def'
                                               }, {
                                                   101: 'ghi',
                                                   103: 'jkl'
                                               }, {
                                                   101:
                                                   'mno',
                                                   200: [{
                                                       201: 'aaa',
                                                       202: 'bbb'
                                                   }]
                                               }]), (99, 'X')]))
     self.assertEquals(
         to_fix('8=FIX.4.2', '9=73', '100=3', '101=abc', '102=def',
                '101=ghi', '103=jkl', '101=mno', '200=1', '201=aaa',
                '202=bbb', '99=X', '10=034'), mess.to_binary())
Esempio n. 5
0
    def test_simple_message(self):
        """ Basic function test. """
        parser = FIXParser(self.receiver,
                           header_fields=[8, 9])

        self.assertFalse(parser.is_parsing)

        # message taken from wikipedia article
        parser.on_data_received(to_fix('8=FIX.4.2',
                                       '9=65',
                                       '35=A',
                                       '49=SERVER',
                                       '56=CLIENT',
                                       '34=177',
                                       '52=20090107-18:15:16',
                                       '98=0',
                                       '108=30',
                                       '10=062'))

        self.assertFalse(parser.is_parsing)
        self.assertEquals(1, self.receiver.count)

        message = self.receiver.last_received_message
        self.assertIsNotNone(message)
        self.assertEquals(10, len(message))
        self.assertTrue(message.verify(fields=[(8, 'FIX.4.2'),
                                               (9, '65'),
                                               (35, 'A'),
                                               (10, '062')]))
Esempio n. 6
0
 def test_bad_protocol_version(self):
     """ Send a bad protocol_version through the protocol. """
     with self.assertRaises(FIXDataError) as context:
         self.protocol.on_data_received(
             to_fix('8=FIX.X.X', '9=25', '35=A', '49=server', '56=client',
                    '10=152'))
     self.assertEquals(8, context.exception.reference_id)
Esempio n. 7
0
 def test_bad_checksum(self):
     """ Send a message with an incorrect checksum field (10). """
     with self.assertRaises(FIXDataError) as context:
         self.protocol.on_data_received(
             to_fix('8=FIX.4.2', '9=25', '35=A', '49=server', '56=client',
                    '10=000'))
     self.assertEquals(10, context.exception.reference_id)
Esempio n. 8
0
    def test_to_binary(self):
        mess = FIXMessage()
        mess[8] = 'FIX.4.2'
        mess[9] = '---'
        mess[35] = 'A'
        mess[49] = 'SERVER'
        mess[56] = 'CLIENT'
        mess[34] = 177
        mess[52] = '20090107-18:15:16'
        mess[98] = 0
        mess[108] = 30
        mess[10] = '---'

        data = mess.to_binary()

        # BodyLength(9) and Checksum(10) should be updated after
        # the to_binary() was called.
        self.assertEquals('65', mess[9])
        self.assertEquals('062', mess[10])

        self.assertEquals(to_fix('8=FIX.4.2',
                                 '9=65',
                                 '35=A',
                                 '49=SERVER',
                                 '56=CLIENT',
                                 '34=177',
                                 '52=20090107-18:15:16',
                                 '98=0',
                                 '108=30',
                                 '10=062'),
                          data)
Esempio n. 9
0
    def test_multiple_message(self):
        """ Receive two messages in one data buffer """
        parser = FIXParser(self.receiver,
                           header_fields=[8, 9])

        self.assertFalse(parser.is_parsing)
        parser.on_data_received(to_fix('8=FIX.4.2',
                                       '9=5',
                                       '35=A',
                                       '10=178',
                                       '8=FIX.4.2',
                                       '9=17',
                                       '35=E',
                                       '99=forsooth',
                                       '10=013'))
        self.assertFalse(parser.is_parsing)
        self.assertEquals(2, self.receiver.count)

        message = self.receiver.last_received_message
        self.assertIsNotNone(message)
        self.assertEquals(5, len(message))
        self.assertTrue(message.verify(fields=[(8, 'FIX.4.2'),
                                               (9, '17'),
                                               (35, 'E'),
                                               (99, 'forsooth'),
                                               (10, '013')]))
Esempio n. 10
0
    def test_one_byte_at_a_time(self):
        """ Receive a message split up into single bytes """
        parser = FIXParser(self.receiver,
                           header_fields=[8, 9])

        text = to_fix('8=FIX.4.2',
                      '9=23',
                      '35=A',
                      '919=this',
                      '955=that',
                      '10=013')
        for c in text:
            parser.on_data_received(c)

        self.assertFalse(parser.is_parsing)
        self.assertEquals(1, self.receiver.count)

        message = self.receiver.last_received_message
        self.assertIsNotNone(message)
        self.assertEquals(6, len(message))
        self.assertTrue(message.verify(fields=[(8, 'FIX.4.2'),
                                               (9, '23'),
                                               (35, 'A'),
                                               (919, 'this'),
                                               (955, 'that'),
                                               (10, '013')]))
Esempio n. 11
0
 def test_nested_group_from_list(self):
     """ Call to_binary() on a nested grouped message from a list """
     # As its difficult to test this, convert the (unordered)
     # dict into an OrderedDict() before inserting (sorting by tag).
     # This makes it easier to do the comparison.
     mess = FIXMessage(
         header_fields=[8, 9],
         source=to_ordered_dict([(8, 'FIX.4.2'),
                                 (100, [{101: 'abc', 102: 'def'},
                                        {101: 'ghi', 103: 'jkl'},
                                        {101: 'mno', 200: [
                                            {201: 'aaa', 202: 'bbb'}]}]),
                                 (99, 'X')]))
     self.assertEquals(to_fix('8=FIX.4.2',
                              '9=73',
                              '100=3',
                              '101=abc',
                              '102=def',
                              '101=ghi',
                              '103=jkl',
                              '101=mno',
                              '200=1',
                              '201=aaa',
                              '202=bbb',
                              '99=X',
                              '10=034'),
                       mess.to_binary())
Esempio n. 12
0
    def test_multiple_nested_groups(self):
        """ Test the receiving of multiple nested groups """
        parser = FIXParser(self.receiver,
                           debug=True,
                           group_fields={100: [101, 102, 200],
                                         200: [201, 202], },
                           header_fields=[8, 9])

        parser.on_data_received(to_fix('8=FIX.4.2',
                                       '9=60',
                                       '100=2',
                                       '101=a',
                                       '102=b',
                                       '200=2',
                                       '201=abc',
                                       '202=def',
                                       '201=zzz',
                                       '101=c',
                                       '102=d',
                                       '10=002'))
        self.assertEquals(1, self.receiver.count)

        message = self.receiver.last_received_message
        print message.store
        self.assertIsNotNone(message)
        self.assertEquals(4, len(message))

        self.assertTrue(100 in message)
        self.assertEquals(2, len(message[100]))

        group = message[100]
        self.assertIsNotNone(group)
        self.assertEquals(2, len(group))
        self.assertEquals(3, len(group[0]))
        self.assertTrue(101 in group[0])
        self.assertTrue(102 in group[0])
        self.assertTrue(200 in group[0])
        self.assertEquals('a', group[0][101])
        self.assertEquals('b', group[0][102])
        self.assertEquals(2, len(group[1]))
        self.assertTrue(101 in group[1])
        self.assertTrue(102 in group[1])
        self.assertTrue(200 not in group[1])
        self.assertEquals('c', group[1][101])
        self.assertEquals('d', group[1][102])

        subgroup = group[0]
        self.assertIsNotNone(subgroup)
        self.assertEquals(3, len(subgroup))
        self.assertEquals(2, len(subgroup[200]))
        subgroup200 = subgroup[200]
        self.assertEquals(2, len(subgroup200[0]))
        self.assertTrue(201 in subgroup200[0])
        self.assertTrue(202 in subgroup200[0])
        self.assertEquals('abc', subgroup200[0][201])
        self.assertEquals('def', subgroup200[0][202])
        self.assertEquals(1, len(subgroup200[1]))
        self.assertTrue(201 in subgroup200[1])
        self.assertTrue(202 not in subgroup200[1])
        self.assertEquals('zzz', subgroup200[1][201])
Esempio n. 13
0
    def test_simple_group_fields(self):
        """ Simple group field testing. """
        parser = FIXParser(self.receiver,
                           group_fields={100: [101, 102, 200],
                                         200: [201, 202], },
                           header_fields=[8, 9])

        parser.on_data_received(to_fix('8=FIX.4.2',
                                       '9=18',
                                       '100=1',
                                       '101=a',
                                       '102=b',
                                       '10=099'))
        self.assertEquals(1, self.receiver.count)

        message = self.receiver.last_received_message
        self.assertIsNotNone(message)
        self.assertEquals(4, len(message))

        self.assertTrue(100 in message)
        self.assertEquals(1, len(message[100]))

        group = message[100]
        self.assertIsNotNone(group)
        self.assertEquals(1, len(group))
        self.assertEquals(2, len(group[0]))
        self.assertTrue(101 in group[0])
        self.assertTrue(102 in group[0])
        self.assertEquals('a', group[0][101])
        self.assertEquals('b', group[0][102])
Esempio n. 14
0
 def test_group_from_list(self):
     """ Call to_binary() on a grouped message from a list """
     mess = FIXMessage(header_fields=[8, 9],
                       source=[(8, 'FIX.4.2'), (9, '25'), (49, 'SERVER'),
                               (56, 'CLIENT'), (99, 'X')])
     self.assertEquals(
         to_fix('8=FIX.4.2', '9=25', '49=SERVER', '56=CLIENT', '99=X',
                '10=239'), mess.to_binary())
Esempio n. 15
0
    def test_message_too_large(self):
        """ Test for too long message """
        parser = FIXParser(self.receiver,
                           header_fields=[8, 9],
                           max_length=100)

        with self.assertRaises(FIXLengthTooLongError):
            parser.on_data_received(to_fix('8=FIX.4.2',
                                           '9=32',
                                           '42=A' + 'BB'*100))
Esempio n. 16
0
    def test_checksum(self):
        self.assertEquals(1, checksum('\x01'))
        self.assertEquals(2, checksum('\x01\x01'))
        self.assertEquals(2, checksum('\xFF\x03'))

        # example taken from wikipedia
        self.assertEquals(
            62,
            checksum(
                to_fix('8=FIX.4.2', '9=65', '35=A', '49=SERVER', '56=CLIENT',
                       '34=177', '52=20090107-18:15:16', '98=0', '108=30')))
Esempio n. 17
0
    def test_message_starts_incorrectly(self):
        """ Message must start with tag 8 """
        parser = FIXParser(self.receiver,
                           header_fields=[8, 9])

        # message does not start with tag 8
        with self.assertRaises(FIXParserError):
            parser.on_data_received(to_fix('18=FIX.4.2',
                                           '9=32',
                                           '8=FIX.4.2',
                                           '35=A',
                                           '10=100'))

        # unexpected tag 8
        with self.assertRaises(FIXParserError):
            parser.on_data_received(to_fix('8=FIX.4.2',
                                           '9=32',
                                           '8=abcdef',
                                           '35=A',
                                           '10=100'))
Esempio n. 18
0
    def test_to_binary_binarydata(self):
        mess = FIXMessage(header_fields=[8, 9])
        mess[8] = 'FIX.4.2'
        mess[9] = '---'
        mess[110] = 2
        mess[111] = '\x01\x02a\xbbbcd'

        data = mess.to_binary()

        self.assertEquals(
            to_fix('8=FIX.4.2', '9=18', '110=2', '111=\x01\x02a\xbbbcd',
                   '10=026'), data)
Esempio n. 19
0
    def test_receive_testrequest(self):
        """ Test receiving testrequest """
        now = datetime.datetime.now() - datetime.timedelta(seconds=2)
        self.protocol._last_send_time = now
        self.protocol._last_received_time = now
        last_time = self.protocol._last_received_time

        self.protocol.filter_heartbeat = False

        self.protocol.on_data_received(to_fix("8=FIX.4.2", "9=13", "35=1", "112=tr1", "10=186"))
        self.assertEquals(1, self.transport.message_received_count)
        self.assertNotEquals(last_time, self.protocol._last_received_time)
Esempio n. 20
0
    def test_parser_reset(self):
        """ Test that the parser resets on an error """
        parser = FIXParser(self.receiver,
                           header_fields=[8, 9])

        # Tag ID is not a number
        self.assertFalse(parser.is_parsing)
        with self.assertRaises(FIXParserError):
            parser.on_data_received(to_fix('8=FIX.4.2',
                                           '9=32',
                                           'abcd=A'))
        self.assertFalse(parser.is_parsing)
Esempio n. 21
0
    def test_to_binary_include(self):
        mess = FIXMessage()
        mess[8] = 'FIX.4.2'
        mess[9] = '---'
        mess[35] = 'A'
        mess[49] = 'SERVER'
        mess[56] = 'CLIENT'
        mess[177] = 'hello'

        data = mess.to_binary(include=[8, 9, 35, 177])
        self.assertEquals(
            to_fix('8=FIX.4.2', '9=15', '35=A', '177=hello', '10=212'), data)
Esempio n. 22
0
    def test_partial_message(self):
        """ Test for partial input. """
        parser = FIXParser(self.receiver,
                           header_fields=[8, 9])

        self.assertFalse(parser.is_parsing)
        self.assertEquals(0, self.receiver.count)
        parser.on_data_received(to_fix('8=FIX.4.2',
                                       '9=32',
                                       '35=A'))
        self.assertEquals(0, self.receiver.count)
        self.assertTrue(parser.is_parsing)
Esempio n. 23
0
    def test_binary_fields(self):
        """ Binary field testing. """
        parser = FIXParser(self.receiver,
                           binary_fields=[1000, 1010],
                           header_fields=[8, 9])

        # Test with embedded binary \x01
        parser.on_data_received(to_fix('8=FIX.4.2',
                                       '9=18',
                                       '1000=5',
                                       '1001=\x01\x02\x03\x04\x05',
                                       '10=066'))
        self.assertEquals(1, self.receiver.count)

        message = self.receiver.last_received_message
        self.assertIsNotNone(message)
        self.assertEquals(5, len(message))
        self.assertTrue(message.verify(fields=[(8, 'FIX.4.2'),
                                               (9, '18'),
                                               (1000, '5'),
                                               (1001, '\x01\x02\x03\x04\x05'),
                                               (10, '066')]))

        # Test with embedded '=' signs
        parser.on_data_received(to_fix('8=FIX.4.2',
                                       '9=18',
                                       '1000=5',
                                       '1001=31=20',
                                       '10=054'))
        self.assertEquals(2, self.receiver.count)

        message = self.receiver.last_received_message
        self.assertIsNotNone(message)
        self.assertEquals(5, len(message))
        self.assertTrue(message.verify(fields=[(8, 'FIX.4.2'),
                                               (9, '18'),
                                               (1000, '5'),
                                               (1001, '31=20'),
                                               (10, '054')]))
Esempio n. 24
0
    def test_bad_syntax(self):
        """ Test for various bad syntax cases """
        parser = FIXParser(self.receiver,
                           header_fields=[8, 9])

        # Tag ID is not a number
        with self.assertRaises(FIXParserError):
            parser.on_data_received(to_fix('8=FIX.4.2',
                                           '9=32',
                                           'abcd=A'))

        # Missing '=' and value portion
        with self.assertRaises(FIXParserError):
            parser.on_data_received(to_fix('8=FIX.4',
                                           '9=32',
                                           '35'))

        # Missing tag ID portion
        with self.assertRaises(FIXParserError):
            parser.on_data_received(to_fix('8=FIX.4',
                                           '9=32',
                                           '=A'))
Esempio n. 25
0
    def test_receive_testrequest(self):
        """ Test receiving testrequest """
        now = datetime.datetime.now() - datetime.timedelta(seconds=2)
        self.protocol._last_send_time = now
        self.protocol._last_received_time = now
        last_time = self.protocol._last_received_time

        self.protocol.filter_heartbeat = False

        self.protocol.on_data_received(
            to_fix('8=FIX.4.2', '9=13', '35=1', '112=tr1', '10=186'))
        self.assertEquals(1, self.transport.message_received_count)
        self.assertNotEquals(last_time, self.protocol._last_received_time)
Esempio n. 26
0
    def test_to_binary_exclude(self):
        mess = FIXMessage()
        mess[8] = 'FIX.4.2'
        mess[9] = '---'
        mess[35] = 'A'
        mess[49] = 'SERVER'
        mess[56] = 'CLIENT'
        mess[99] = 'X'
        mess[177] = 'hello'

        data = mess.to_binary(exclude=[35, 177])
        self.assertEquals(
            to_fix('8=FIX.4.2', '9=25', '49=SERVER', '56=CLIENT', '99=X',
                   '10=239'), data)
Esempio n. 27
0
    def test_header_fields_in_order(self):
        """ Test for out-of-order header fields """
        self.protocol.on_data_received(to_fix("8=FIX.4.2", "9=10", "49=s", "35=A", "10=252"))
        self.assertIsNotNone(self.transport.last_message_received)
        items = flatten(self.transport.last_message_received)

        # the order should be restored because the header fields will
        # have been pre-added.
        self.assertEquals(5, len(items))
        self.assertEquals(8, items[0][0])
        self.assertEquals(9, items[1][0])
        self.assertEquals(35, items[2][0])
        self.assertEquals(49, items[3][0])
        self.assertEquals(10, items[4][0])
Esempio n. 28
0
    def test_header_fields_in_order(self):
        """ Test for out-of-order header fields """
        self.protocol.on_data_received(
            to_fix('8=FIX.4.2', '9=10', '49=s', '35=A', '10=252'))
        self.assertIsNotNone(self.transport.last_message_received)
        items = flatten(self.transport.last_message_received)

        # the order should be restored because the header fields will
        # have been pre-added.
        self.assertEquals(5, len(items))
        self.assertEquals(8, items[0][0])
        self.assertEquals(9, items[1][0])
        self.assertEquals(35, items[2][0])
        self.assertEquals(49, items[3][0])
        self.assertEquals(10, items[4][0])
Esempio n. 29
0
    def test_message_binary_too_long(self):
        """ Test for message with missing binary data """
        parser = FIXParser(self.receiver,
                           header_fields=[8, 9],
                           binary_fields=[1000],
                           max_length=100)

        # length too short
        with self.assertRaises(FIXLengthTooLongError):
            parser.on_data_received(to_fix('8=FIX.4.2',
                                           '9=32',
                                           '42=A',
                                           '1000=128',
                                           '1001=abababababab',
                                           '10=000'))
Esempio n. 30
0
    def test_to_binary_binarydata(self):
        mess = FIXMessage(header_fields=[8, 9])
        mess[8] = 'FIX.4.2'
        mess[9] = '---'
        mess[110] = 2
        mess[111] = '\x01\x02a\xbbbcd'

        data = mess.to_binary()

        self.assertEquals(to_fix('8=FIX.4.2',
                                 '9=18',
                                 '110=2',
                                 '111=\x01\x02a\xbbbcd',
                                 '10=026'),
                          data)
Esempio n. 31
0
 def test_group_from_list(self):
     """ Call to_binary() on a grouped message from a list """
     mess = FIXMessage(header_fields=[8, 9],
                       source=[(8, 'FIX.4.2'),
                               (9, '25'),
                               (49, 'SERVER'),
                               (56, 'CLIENT'),
                               (99, 'X')])
     self.assertEquals(to_fix('8=FIX.4.2',
                              '9=25',
                              '49=SERVER',
                              '56=CLIENT',
                              '99=X',
                              '10=239'),
                       mess.to_binary())
Esempio n. 32
0
    def test_filter_testrequest(self):
        """ Test testrequest filtering """
        now = datetime.datetime.now() - datetime.timedelta(seconds=1)
        self.protocol._last_send_time = now - datetime.timedelta(minutes=1)
        self.protocol._last_received_time = now
        last_time = self.protocol._last_received_time

        # start heartbeat processing
        self.protocol.heartbeat = 5  # time in secs
        self.protocol.filter_heartbeat = True

        self.protocol.on_data_received(to_fix("8=FIX.4.2", "9=13", "35=1", "112=tr1", "10=186"))

        self.assertEquals(0, self.transport.message_received_count)
        self.assertNotEquals(last_time, self.protocol._last_received_time)
Esempio n. 33
0
    def test_filter_testrequest(self):
        """ Test testrequest filtering """
        now = datetime.datetime.now() - datetime.timedelta(seconds=1)
        self.protocol._last_send_time = now - datetime.timedelta(minutes=1)
        self.protocol._last_received_time = now
        last_time = self.protocol._last_received_time

        # start heartbeat processing
        self.protocol.heartbeat = 5  # time in secs
        self.protocol.filter_heartbeat = True

        self.protocol.on_data_received(
            to_fix('8=FIX.4.2', '9=13', '35=1', '112=tr1', '10=186'))

        self.assertEquals(0, self.transport.message_received_count)
        self.assertNotEquals(last_time, self.protocol._last_received_time)
Esempio n. 34
0
    def test_checksum(self):
        self.assertEquals(1, checksum('\x01'))
        self.assertEquals(2, checksum('\x01\x01'))
        self.assertEquals(2, checksum('\xFF\x03'))

        # example taken from wikipedia
        self.assertEquals(62,
                          checksum(to_fix('8=FIX.4.2',
                                          '9=65',
                                          '35=A',
                                          '49=SERVER',
                                          '56=CLIENT',
                                          '34=177',
                                          '52=20090107-18:15:16',
                                          '98=0',
                                          '108=30')))
Esempio n. 35
0
    def test_to_binary_include(self):
        mess = FIXMessage()
        mess[8] = 'FIX.4.2'
        mess[9] = '---'
        mess[35] = 'A'
        mess[49] = 'SERVER'
        mess[56] = 'CLIENT'
        mess[177] = 'hello'

        data = mess.to_binary(include=[8, 9, 35, 177])
        self.assertEquals(to_fix('8=FIX.4.2',
                                 '9=15',
                                 '35=A',
                                 '177=hello',
                                 '10=212'),
                          data)
Esempio n. 36
0
    def test_to_binary_group(self):
        """ Call to_binary() on a grouped message """
        mess = FIXMessage(header_fields=[8, 9])
        tags = collections.OrderedDict()
        mess[8] = 'FIX.4.2'
        mess[9] = '---'
        tags[110] = 2
        tags[111] = 'abcd'

        mess[100] = [
            tags,
        ]
        data = mess.to_binary()

        self.assertEquals(
            to_fix('8=FIX.4.2', '9=21', '100=1', '110=2', '111=abcd',
                   '10=086'), data)
Esempio n. 37
0
    def test_to_binary_exclude(self):
        mess = FIXMessage()
        mess[8] = 'FIX.4.2'
        mess[9] = '---'
        mess[35] = 'A'
        mess[49] = 'SERVER'
        mess[56] = 'CLIENT'
        mess[99] = 'X'
        mess[177] = 'hello'

        data = mess.to_binary(exclude=[35, 177])
        self.assertEquals(to_fix('8=FIX.4.2',
                                 '9=25',
                                 '49=SERVER',
                                 '56=CLIENT',
                                 '99=X',
                                 '10=239'),
                          data)
Esempio n. 38
0
    def test_grouped_binary_fields(self):
        """ Test binary fields that are in a group. """
        parser = FIXParser(self.receiver,
                           debug=True,
                           group_fields={200: [201, 202, 99, 100]},
                           binary_fields=[99],
                           header_fields=[8, 9])

        text = to_fix('8=FIX.4.2',
                      '9=80',
                      '35=A',
                      '200=2',
                      '201=aabc',
                      '99=5',
                      '100=abcde',
                      '201=zzzaa',
                      '202=myname',
                      '99=5',
                      '100=zztop',
                      '955=that',
                      '10=201')
        parser.on_data_received(text)
        self.assertFalse(parser.is_parsing)

        self.assertEquals(1, self.receiver.count)

        message = self.receiver.last_received_message
        self.assertIsNotNone(message)
        self.assertEquals(6, len(message))
        self.assertEquals(2, len(message[200]))
        self.assertTrue(200 in message)
        self.assertTrue(955 in message)
        subgroup = message[200][0]
        self.assertEquals(3, len(subgroup))
        self.assertTrue(201 in subgroup)
        self.assertTrue(99 in subgroup)
        self.assertTrue(100 in subgroup)
        subgroup = message[200][1]
        self.assertEquals(4, len(subgroup))
        self.assertTrue(201 in subgroup)
        self.assertTrue(202 in subgroup)
        self.assertTrue(99 in subgroup)
        self.assertTrue(100 in subgroup)
Esempio n. 39
0
    def test_to_binary_group(self):
        """ Call to_binary() on a grouped message """
        mess = FIXMessage(header_fields=[8, 9])
        tags = collections.OrderedDict()
        mess[8] = 'FIX.4.2'
        mess[9] = '---'
        tags[110] = 2
        tags[111] = 'abcd'

        mess[100] = [tags, ]
        data = mess.to_binary()

        self.assertEquals(to_fix('8=FIX.4.2',
                                 '9=21',
                                 '100=1',
                                 '110=2',
                                 '111=abcd',
                                 '10=086'),
                          data)
Esempio n. 40
0
    def test_header_fields(self):
        """ Header field testing. """
        parser = FIXParser(self.receiver,
                           header_fields=[8, 9, 320])

        parser.on_data_received(to_fix('8=FIX.4.2',
                                       '9=5',
                                       '35=A',
                                       '10=178'))
        self.assertEquals(1, self.receiver.count)

        message = self.receiver.last_received_message
        self.assertIsNotNone(message)
        message[320] = 'hello there'
        self.assertEquals(5, len(message))

        # verify the order of the message
        items = [(k, v) for k, v in message.items()]
        self.assertEquals(8, items[0][0])
        self.assertEquals(9, items[1][0])
        self.assertEquals(320, items[2][0])
Esempio n. 41
0
    def test_multiple_groups(self):
        """ Test the receiving of multiple groups """
        parser = FIXParser(self.receiver,
                           group_fields={100: [101, 102, 200],
                                         200: [201, 202], },
                           header_fields=[8, 9])

        parser.on_data_received(to_fix('8=FIX.4.2',
                                       '9=32',
                                       '100=2',
                                       '101=a',
                                       '102=b',
                                       '101=aa',
                                       '102=bb',
                                       '10=135'))
        self.assertEquals(1, self.receiver.count)

        message = self.receiver.last_received_message
        self.assertIsNotNone(message)
        self.assertEquals(4, len(message))

        self.assertTrue(100 in message)
        self.assertEquals(2, len(message[100]))

        group = message[100]
        self.assertIsNotNone(group)
        self.assertEquals(2, len(group))
        self.assertEquals(2, len(group[0]))
        self.assertTrue(101 in group[0])
        self.assertTrue(102 in group[0])
        self.assertEquals('a', group[0][101])
        self.assertEquals('b', group[0][102])
        self.assertEquals(2, len(group[1]))
        self.assertTrue(101 in group[1])
        self.assertTrue(102 in group[1])
        self.assertEquals('aa', group[1][101])
        self.assertEquals('bb', group[1][102])
Esempio n. 42
0
 def test_to_fix(self):
     data = to_fix('a', 'b', 'c')
     self.assertEquals('a\x01b\x01c\x01', data)