def test_loader(): """Test the loader""" assert load_yaml_protocol('etc/FIX40.yaml') is not None assert load_yaml_protocol('etc/FIX41.yaml') is not None assert load_yaml_protocol('etc/FIX42.yaml') is not None assert load_yaml_protocol('etc/FIX43.yaml') is not None assert load_yaml_protocol('etc/FIX44.yaml') is not None
def test_loader_is_type_enum(): """Tests for is_type_enum""" assert load_yaml_protocol('etc/FIX44.yaml', is_type_enum={ValueType.BOOLEAN: False}) is not None assert load_yaml_protocol('etc/FIX44.yaml', is_type_enum={'BOOLEAN': False}) is not None
def test_fix_message_factory(): """Test the message factory""" protocol = load_yaml_protocol('etc/FIX44.yaml', is_millisecond_time=True, is_float_decimal=True, is_type_enum={ValueType.BOOLEAN: False}) factory = FixMessageFactory(protocol, "SENDER", "TARGET") sending_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=timezone.utc) fix_messages = [ factory.create('LOGON', 42, sending_time, { 'EncryptMethod': "NONE", 'HeartBtInt': 30 }), factory.create('LOGOUT', 42, sending_time, {}), factory.create('HEARTBEAT', 43, sending_time, {}), factory.create('RESEND_REQUEST', 44, sending_time, { 'BeginSeqNo': 10, 'EndSeqNo': 12 }), factory.create('TEST_REQUEST', 45, sending_time, {'TestReqID': "This is not a test"}), factory.create('SEQUENCE_RESET', 46, sending_time, { 'GapFillFlag': False, 'NewSeqNo': 12 }) ] for fix_message in fix_messages: encoded_message = fix_message.encode(regenerate_integrity=True) roundtrip = FixMessage.decode(protocol, encoded_message) assert fix_message.message == roundtrip.message
def test_encode_logon(): """Test encoding""" protocol = load_yaml_protocol('etc/FIX44.yaml', is_millisecond_time=True, is_float_decimal=True, is_type_enum={ValueType.BOOLEAN: False}) sending_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=timezone.utc) messages = [{ 'MsgType': 'LOGON', 'MsgSeqNum': 42, 'SenderCompID': "SENDER", 'TargetCompID': "TARGET", 'SendingTime': sending_time, 'EncryptMethod': "NONE", 'HeartBtInt': 30 }, { 'MsgType': 'LOGOUT', 'MsgSeqNum': 43, 'SenderCompID': "SENDER", 'TargetCompID': "TARGET", 'SendingTime': sending_time }, { 'MsgType': 'HEARTBEAT', 'MsgSeqNum': 43, 'SenderCompID': "SENDER", 'TargetCompID': "TARGET", 'SendingTime': sending_time }, { 'MsgType': 'RESEND_REQUEST', 'MsgSeqNum': 42, 'SenderCompID': "SENDER", 'TargetCompID': "TARGET", 'SendingTime': sending_time, 'BeginSeqNo': 10, 'EndSeqNo': 12 }, { 'MsgType': 'TEST_REQUEST', 'MsgSeqNum': 42, 'SenderCompID': "SENDER", 'TargetCompID': "TARGET", 'SendingTime': sending_time, 'TestReqID': "This is not a test" }, { 'MsgType': 'SEQUENCE_RESET', 'MsgSeqNum': 42, 'SenderCompID': "SENDER", 'TargetCompID': "TARGET", 'SendingTime': sending_time, 'GapFillFlag': False, 'NewSeqNo': 12 }] for message in messages: fix_message = FixMessage(protocol, message) encoded_message = fix_message.encode(regenerate_integrity=True) roundtrip = FixMessage.decode(protocol, encoded_message) assert fix_message.message == roundtrip.message
def test_messages(): """Test decoding messages""" messages = [ b'8=FIX.4.4|9=94|35=3|49=A|56=AB|128=B1|34=214|50=U1|52=20100304-09:42:23.130|45=176|371=15|372=X|373=1|58=txt|10=058|', b'8=FIX.4.4|9=117|35=AD|49=A|56=B|34=2|50=1|57=M|52=20100219-14:33:32.258|568=1|569=0|263=1|580=1|75=20100218|60=20100218-00:00:00.000|10=202|', b'8=FIX.4.4|9=122|35=D|49=CLIENT12|56=B|34=215|52=20100225-19:41:57.316|11=13346|1=Marcel|21=1|54=1|60=20100225-19:39:52.020|40=2|44=5|59=0|10=072|', ] protocol = load_yaml_protocol( 'etc/FIX44.yaml', is_millisecond_time=True, is_float_decimal=True ) for buf in messages: msg = FixMessage.decode( protocol, buf, sep=b'|', strict=True, validate=True, convert_sep_for_checksum=True) round_trip = msg.encode( sep=b'|', regenerate_integrity=True, convert_sep_for_checksum=True) assert buf == round_trip
def protocol_42(): return load_yaml_protocol('etc/FIX42.yaml', is_millisecond_time=False, is_float_decimal=True)