コード例 #1
0
def test_helpers():
    assert FIX.get_field_name(35) == 'MsgType'
    assert FIX.get_field_name('35') == 'MsgType'
    assert FIX.get_field_number('MsgType') == '35'

    assert FIX.get_field_name(11) == 'ClOrdID'
    assert FIX.get_field_name('11') == 'ClOrdID'
    assert FIX.get_field_number('ClOrdID') == '11'

    assert FIX.get_message_name('A') == 'Logon'
    assert FIX.get_message_name('D') == 'NewOrderSingle'
コード例 #2
0
ファイル: test_phixlib.py プロジェクト: nagyist/phixlib
def test_helpers():
    assert FIX.get_field_name(35) == "MsgType"
    assert FIX.get_field_name("35") == "MsgType"
    assert FIX.get_field_number("MsgType") == "35"

    assert FIX.get_field_name(11) == "ClOrdID"
    assert FIX.get_field_name("11") == "ClOrdID"
    assert FIX.get_field_number("ClOrdID") == "11"

    assert FIX.get_message_name("A") == "Logon"
    assert FIX.get_message_name("D") == "NewOrderSingle"
コード例 #3
0
def test_registry():

    assert FIX.FIXMessage
    assert FIX.FIXMessage.Header
    assert FIX.FIXMessage.Trailer
    assert not FIX.FIXMessage.msgcat
    assert not FIX.FIXMessage.msgtype
    assert not FIX.FIXMessage.name
    assert not FIX.FIXMessage._all

    for version in FIX._versions:
        assert FIX[
            version].FIXMessage, "%s does not have a FIXMessage registered" % (
                version, )
        assert FIX[version].FIXMessage.Header
        assert FIX[version].FIXMessage.Trailer
        assert not FIX[version].FIXMessage.msgcat
        assert not FIX[version].FIXMessage.msgtype
        assert not FIX[version].FIXMessage.name
        assert not FIX[version].FIXMessage._all
        assert issubclass(FIX[version].FIXMessage, FIX.FIXMessage)

    assert 'FIX42' in FIX
    assert 'FIX.4.2' in FIX
    assert 'NewOrderSingle' in FIX.FIX42
    assert 'NewOrderSingle' in FIX['FIX.4.2']
    assert FIX.FIX42.NewOrderSingle
    assert FIX.FIX42.Messages.NewOrderSingle

    assert FIX.FIX42.NewOrderSingle.msgtype == 'D'
    assert FIX.FIX42.Messages.NewOrderSingle.msgtype == 'D'
    assert FIX.FIX42.NewOrderSingle.name == 'NewOrderSingle'
    assert FIX.FIX42.Messages.NewOrderSingle.name == 'NewOrderSingle'

    assert FIX.FIX42.OrdType.number == '40'
    assert FIX.FIX42.OrdType.name == 'OrdType'
    assert FIX.FIX42.OrdType.type == 'CHAR'
    assert FIX.FIX42.OrdType.MARKET == '1'
    assert FIX.FIX42.OrdType.enums['1'] == 'MARKET'
    assert '1' in FIX.FIX42.OrdType.enums

    assert FIX.FIX42.NewOrderSingle.OrdType
    assert FIX.FIX42.NewOrderSingle.OrdType.MARKET == FIX.FIX42.OrdType.MARKET

    assert issubclass(FIX.FIX42.MassQuote, FIXMessage)
    assert issubclass(FIX.FIX42.MassQuote.NoQuoteSets, Group)
    assert issubclass(FIX.FIX42.MassQuote.NoQuoteSets, FIX.FIX42.NoQuoteSets)
    assert issubclass(FIX.FIX42.MassQuote.NoQuoteSets.NoQuoteEntries, Group)
    assert issubclass(
        FIX.FIX42.MassQuote.NoQuoteSets.NoQuoteEntries.QuoteEntryID, Field)

    assert issubclass(FIX.FIX42.NoQuoteSets, Field)
    assert not issubclass(FIX.FIX42.NoQuoteSets, Group)

    assert id(FIX.FIX42.OrdType.enums) == id(
        FIX.FIX42.NewOrderSingle.OrdType.enums)
    assert id(FIX.FIX42.OrdType.enums) == id(
        FIX.FIX42.MassQuote.NoQuoteSets.NoQuoteEntries.OrdType.enums)

    assert FIX.get_field_number(
        FIX.FIX42.OrdType.name) == FIX.FIX42.OrdType.number
    assert not FIX.get_field_number(-1)

    assert FIX.get_field_name(
        FIX.FIX42.OrdType.number) == FIX.FIX42.OrdType.name
    assert not FIX.get_field_name(-1)

    assert FIX.get_message_name(
        FIX.FIX42.NewOrderSingle.msgtype) == FIX.FIX42.NewOrderSingle.name
    assert not FIX.get_message_name('NotAMessage')

    assert FIX.get_message_type(
        FIX.FIX42.NewOrderSingle.name) == FIX.FIX42.NewOrderSingle.msgtype
    assert not FIX.get_message_type('_')
コード例 #4
0
def test_parser():
    expected = {
        'BeginString':
        'FIX.4.2',
        'BodyLength':
        '295',
        'CheckSum':
        '215',
        'MsgSeqNum':
        '2',
        'MsgType':
        'i',
        'NoQuoteSets': [{
            'NoQuoteEntries': [{
                'BidSize': '1000000',
                'BidSpotRate': '1.4363',
                'OfferSize': '900000',
                'OfferSpotRate': '1.4365',
                'QuoteEntryID': '0'
            }, {
                'BidSize': '7000000',
                'BidSpotRate': '1.4363',
                'OfferSize': '800000',
                'OfferSpotRate': '1.4365',
                'QuoteEntryID': '1'
            }],
            'QuoteSetID':
            '123'
        }, {
            'NoQuoteEntries': [{
                'BidSize': '1000000',
                'BidSpotRate': '1.4363',
                'OfferSize': '900000',
                'OfferSpotRate': '1.4365',
                'QuoteEntryID': '2'
            }, {
                'BidSize': '7000000',
                'BidSpotRate': '1.4363',
                'OfferSize': '800000',
                'OfferSpotRate': '1.4365',
                'QuoteEntryID': '3'
            }],
            'QuoteSetID':
            '234'
        }],
        'QuoteID':
        '1',
        'SenderCompID':
        'PXMD',
        'SendingTime':
        '20140922-14:48:49.825',
        'TargetCompID':
        'Q037'
    }

    formatted = '''8=FIX.4.2|9=295|35=i|49=PXMD|56=Q037|34=2|52=20140922-14:48:49.825|117=1|296=2|302=123|295=2|299=0|134=1000000|135=900000|188=1.4363|190=1.4365|299=1|134=7000000|135=800000|188=1.4363|190=1.4365|302=234|295=2|299=2|134=1000000|135=900000|188=1.4363|190=1.4365|299=3|134=7000000|135=800000|188=1.4363|190=1.4365|10=215|'''
    assert parse_message(formatted) == expected, pprint(
        parse_message(formatted))

    message = FIX.FIX42.MassQuote(**expected)
    assert repr(message) == formatted

    message = FIX.FIXMessage(**expected)
    assert repr(message) == formatted

    fromstring = FIX.FIX42.MassQuote.fromstring(formatted)
    assert repr(fromstring) == formatted

    fromstring = FIX.FIXMessage.fromstring(formatted)
    assert repr(fromstring) == formatted

    # since this is going to mess up the CheckSum and change the MsgType
    # field as rendered in the formatted string, let's account for that

    fromstring = FIX.FIX42.MassQuote.fromstring(formatted, MsgType='A')
    assert repr(fromstring)[:-4] == formatted.replace('35=i', '35=A')[:-4]
    assert isinstance(fromstring, FIX.FIX42.MassQuote)
    assert not isinstance(fromstring, FIX.FIX42.Logon)

    fromstring = FIX.FIXMessage.fromstring(formatted, MsgType='A')
    #assert repr(fromstring)[:-4] == formatted.replace('35=i', '35=A')[:-4]
    assert isinstance(fromstring, FIX.FIX42.Logon)

    expected = {
        'BeginString':
        'FIX.4.2',
        'BodyLength':
        '156',
        'CheckSum':
        '228',
        'MsgSeqNum':
        '2',
        'MsgType':
        'J',
        'NoAllocs': [{
            'AllocAccount': 'Marcin',
            'AllocShares': '10',
            'NoMiscFees': [{
                'MiscFeeAmt': '7.99'
            }]
        }, {
            'AllocAccount': 'Jason',
            'AllocShares': '5'
        }],
        'NoOrders': [{
            'ClOrdID': 'C11111',
            'OrderID': 'O11111'
        }, {
            'ClOrdID': 'C22222',
            'OrderID': 'O22222'
        }, {
            'OrderID': 'O33333'
        }],
        'SenderCompID':
        'PXMD',
        'SendingTime':
        '20140922-14:48:49.825',
        'TargetCompID':
        'Q037'
    }

    formatted = '''8=FIX.4.2|9=156|35=J|49=PXMD|56=Q037|34=2|52=20140922-14:48:49.825|73=3|11=C11111|37=O11111|11=C22222|37=O22222|37=O33333|78=2|79=Marcin|80=10|136=1|137=7.99|79=Jason|80=5|10=228|'''
    assert parse_message(formatted) == expected, pprint(
        parse_message(formatted))

    message = FIX.FIX42.Allocation(**expected)
    assert repr(message) == formatted

    message = FIX.FIXMessage(**expected)
    assert repr(message) == formatted

    fromstring = FIX.FIX42.Allocation.fromstring(formatted)
    assert repr(fromstring) == formatted

    fromstring = FIX.FIXMessage.fromstring(formatted)
    assert repr(fromstring) == formatted

    expected = {
        'BeginString':
        'FIX.4.2',
        'BodyLength':
        '182',
        'CheckSum':
        '005',
        'MsgSeqNum':
        '2',
        'MsgType':
        'J',
        'NoAllocs': [
            {
                'AllocAccount': 'Marcin',
                'AllocShares': '10',
                'NoMiscFees': [{
                    'MiscFeeAmt': '7.99'
                }]
            },
            {
                'AllocAccount': 'Jason',
                'AllocShares': '5'
            },
            {
                'AllocShares': '10'
            },
            {
                'AllocAccount': 'Tester'
            },
        ],
        'NoOrders': [{
            'ClOrdID': 'C11111',
            'OrderID': 'O11111'
        }, {
            'ClOrdID': 'C22222',
            'OrderID': 'O22222'
        }, {
            'OrderID': 'O33333'
        }, {
            'ClOrdID': 'O44444'
        }],
        'SenderCompID':
        'PXMD',
        'SendingTime':
        '20140922-14:48:49.825',
        'TargetCompID':
        'Q037'
    }

    formatted = '8=FIX.4.2|9=182|35=J|49=PXMD|56=Q037|34=2|52=20140922-14:48:49.825|73=4|11=C11111|37=O11111|11=C22222|37=O22222|37=O33333|11=O44444|78=4|79=Marcin|80=10|136=1|137=7.99|79=Jason|80=5|80=10|79=Tester|10=005|'
    assert parse_message(formatted) == expected, pprint(
        parse_message(formatted))

    message = FIX.FIX42.Allocation(**expected)
    assert repr(message) == formatted

    message = FIX.FIXMessage(**expected)
    assert repr(message) == formatted

    fromstring = FIX.FIX42.Allocation.fromstring(formatted)
    assert repr(fromstring) == formatted

    fromstring = FIX.FIXMessage.fromstring(formatted)
    assert repr(fromstring) == formatted

    #FIX.register_version('phixlib/spec/FIX50SP2.xml')
    #fromstring = FIX.FIX50.AllocationInstruction.fromstring(formatted, BeginString='FIX.5.0')
    #assert repr(fromstring)[9:-7] == formatted[9:-7]
    #print repr(fromstring)
    '''
    expected = {
         'BeginString': 'FIX.4.2',
         'BodyLength': '197',
         'CheckSum': '225',
         'MsgSeqNum': '2',
         'MsgType': 'BBBBBBBBBBBBBBBB',
         'NoAllocs': [{'AllocAccount': 'Marcin',
                       'AllocShares': '10',
                       'NoMiscFees': [{'MiscFeeAmt': '7.99'}]},
                      {'AllocAccount': 'Jason', 'AllocShares': '5'},
                      {'AllocShares': '10'},
                      {'AllocAccount': 'Tester'},
                      ],
         'NoOrders': [{'ClOrdID': 'C11111', 'OrderID': 'O11111'},
                      {'ClOrdID': 'C22222', 'OrderID': 'O22222'},
                      {'OrderID': 'O33333'},
                      {'ClOrdID': 'O44444'}],
         'SenderCompID': 'PXMD',
         'SendingTime': '20140922-14:48:49.825',
         'TargetCompID': 'Q037'}

    message.header._initialized['MsgType'].value = 'BBBBBBBBBBBBBBBB'
    formatted = '8=FIX.4.2|9=197|35=BBBBBBBBBBBBBBBB|49=PXMD|56=Q037|34=2|52=20140922-14:48:49.825|73=4|11=C11111|37=O11111|11=C22222|37=O22222|37=O33333|11=O44444|78=4|79=Marcin|80=10|136=1|137=7.99|79=Jason|80=5|80=10|79=Tester|10=225|'
    assert parse_message(formatted) == expected, pprint(parse_message(formatted))
    '''

    expected = {
        'BeginString': 'FIX.4.2',
        'BodyLength': '74',
        'CheckSum': '213',
        'EncryptMethod': '1',
        'HeartBtInt': '3503',
        'MsgType': 'A',
        'RawData': 'AAAAAAAAAAAAAAAA\001AAA',
        'RawDataLength': '20',
        'SendingTime': '20150407-04:12:54.885'
    }

    formatted = '8=FIX.4.2\0019=74\00135=A\00152=20150407-04:12:54.885\00198=1\001108=3503\00195=20\00196=AAAAAAAAAAAAAAAA\001AAA\00110=213\001'
    assert parse_message(formatted) == expected, pprint(
        parse_message(formatted))

    fromstring = FIX.FIX42.Logon.fromstring(formatted)
    assert str(fromstring) == formatted
コード例 #5
0
ファイル: test_phixlib.py プロジェクト: nagyist/phixlib
def test_registry():

    assert FIX.FIXMessage
    assert FIX.FIXMessage.Header
    assert FIX.FIXMessage.Trailer
    assert not FIX.FIXMessage.msgcat
    assert not FIX.FIXMessage.msgtype
    assert not FIX.FIXMessage.name
    assert not FIX.FIXMessage._all

    for version in FIX._versions:
        assert FIX[version].FIXMessage, "%s does not have a FIXMessage registered" % (version,)
        assert FIX[version].FIXMessage.Header
        assert FIX[version].FIXMessage.Trailer
        assert not FIX[version].FIXMessage.msgcat
        assert not FIX[version].FIXMessage.msgtype
        assert not FIX[version].FIXMessage.name
        assert not FIX[version].FIXMessage._all
        assert issubclass(FIX[version].FIXMessage, FIX.FIXMessage)

    assert "FIX42" in FIX
    assert "FIX.4.2" in FIX
    assert "NewOrderSingle" in FIX.FIX42
    assert "NewOrderSingle" in FIX["FIX.4.2"]
    assert FIX.FIX42.NewOrderSingle
    assert FIX.FIX42.Messages.NewOrderSingle

    assert FIX.FIX42.NewOrderSingle.msgtype == "D"
    assert FIX.FIX42.Messages.NewOrderSingle.msgtype == "D"
    assert FIX.FIX42.NewOrderSingle.name == "NewOrderSingle"
    assert FIX.FIX42.Messages.NewOrderSingle.name == "NewOrderSingle"

    assert FIX.FIX42.OrdType.number == "40"
    assert FIX.FIX42.OrdType.name == "OrdType"
    assert FIX.FIX42.OrdType.type == "CHAR"
    assert FIX.FIX42.OrdType.MARKET == "1"
    assert FIX.FIX42.OrdType.enums["1"] == "MARKET"
    assert "1" in FIX.FIX42.OrdType.enums

    assert FIX.FIX42.NewOrderSingle.OrdType
    assert FIX.FIX42.NewOrderSingle.OrdType.MARKET == FIX.FIX42.OrdType.MARKET

    assert issubclass(FIX.FIX42.MassQuote, FIXMessage)
    assert issubclass(FIX.FIX42.MassQuote.NoQuoteSets, Group)
    assert issubclass(FIX.FIX42.MassQuote.NoQuoteSets, FIX.FIX42.NoQuoteSets)
    assert issubclass(FIX.FIX42.MassQuote.NoQuoteSets.NoQuoteEntries, Group)
    assert issubclass(FIX.FIX42.MassQuote.NoQuoteSets.NoQuoteEntries.QuoteEntryID, Field)

    assert issubclass(FIX.FIX42.NoQuoteSets, Field)
    assert not issubclass(FIX.FIX42.NoQuoteSets, Group)

    assert id(FIX.FIX42.OrdType.enums) == id(FIX.FIX42.NewOrderSingle.OrdType.enums)
    assert id(FIX.FIX42.OrdType.enums) == id(FIX.FIX42.MassQuote.NoQuoteSets.NoQuoteEntries.OrdType.enums)

    assert FIX.get_field_number(FIX.FIX42.OrdType.name) == FIX.FIX42.OrdType.number
    assert not FIX.get_field_number(-1)

    assert FIX.get_field_name(FIX.FIX42.OrdType.number) == FIX.FIX42.OrdType.name
    assert not FIX.get_field_name(-1)

    assert FIX.get_message_name(FIX.FIX42.NewOrderSingle.msgtype) == FIX.FIX42.NewOrderSingle.name
    assert not FIX.get_message_name("NotAMessage")

    assert FIX.get_message_type(FIX.FIX42.NewOrderSingle.name) == FIX.FIX42.NewOrderSingle.msgtype
    assert not FIX.get_message_type("_")