Пример #1
0
    def testPickle(self):
        msg = FIXMessage("AB")
        msg.setField("45", "dgd")
        msg.setField("32", "aaaa")
        msg.setField("323", "bbbb")

        rptgrp1 = FIXContext()
        rptgrp1.setField("611", "aaa")
        rptgrp1.setField("612", "bbb")
        rptgrp1.setField("613", "ccc")

        msg.addRepeatingGroup("444", rptgrp1, 0)

        str = pickle.dumps(msg)

        msg2 = pickle.loads(str)
        self.assertEqual(msg, msg2)
Пример #2
0
    def testPickle(self):
        msg = FIXMessage("AB")
        msg.setField("45", "dgd")
        msg.setField("32", "aaaa")
        msg.setField("323", "bbbb")

        rptgrp1 = FIXContext()
        rptgrp1.setField("611", "aaa")
        rptgrp1.setField("612", "bbb")
        rptgrp1.setField("613", "ccc")

        msg.addRepeatingGroup("444", rptgrp1, 0)

        str = pickle.dumps(msg)

        msg2 = pickle.loads(str)
        self.assertEqual(msg, msg2)
Пример #3
0
    def testAddExtractMsg(self):
        journal = Journaler()

        msg = FIXMessage("AB")
        msg.setField("45", "dgd")
        msg.setField("32", "aaaa")
        msg.setField("323", "bbbb")

        rptgrp1 = FIXContext()
        rptgrp1.setField("611", "aaa")
        rptgrp1.setField("612", "bbb")
        rptgrp1.setField("613", "ccc")

        msg.addRepeatingGroup("444", rptgrp1, 0)
        session = FIXSession(1, "S1", "T1")
        for i in range(0, 5):
            msg.setField("34", str(i))
            journal.persistMsg(msg, session, MessageDirection.OUTBOUND)

        msg = journal.recoverMsg(session, MessageDirection.OUTBOUND, 1)
Пример #4
0
    def testAddExtractMsg(self):
        journal = Journaler()

        msg = FIXMessage("AB")
        msg.setField("45", "dgd")
        msg.setField("32", "aaaa")
        msg.setField("323", "bbbb")

        rptgrp1 = FIXContext()
        rptgrp1.setField("611", "aaa")
        rptgrp1.setField("612", "bbb")
        rptgrp1.setField("613", "ccc")

        msg.addRepeatingGroup("444", rptgrp1, 0)
        session = FIXSession(1, "S1", "T1")
        for i in range(0, 5):
            msg.setField("34", str(i))
            journal.persistMsg(msg, session, MessageDirection.OUTBOUND)

        msg = journal.recoverMsg(session, MessageDirection.OUTBOUND, 1)
Пример #5
0
    def __init__(self):
        self.isServer = False
        self.messages = []

        protocol = importlib.import_module("pyfix.FIX44")
        self.codec = Codec(protocol)

        s = 1
        mock_session = mock.Mock()
        mock_session.senderCompId = "sender"
        mock_session.targetCompId = "target"
        mock_session.allocateSndSeqNo.return_value = s

        msg = FIXMessage(self.codec.protocol.msgtype.NEWORDERSINGLE)
        msg.setField(self.codec.protocol.fixtags.Price, "123.45")
        msg.setField(self.codec.protocol.fixtags.OrderQty, 9876)
        msg.setField(self.codec.protocol.fixtags.Symbol, "VOD.L")
        msg.setField(self.codec.protocol.fixtags.SecurityID, "GB00BH4HKS39")
        msg.setField(self.codec.protocol.fixtags.SecurityIDSource, "4")
        msg.setField(self.codec.protocol.fixtags.Symbol, "VOD.L")
        msg.setField(self.codec.protocol.fixtags.Account, "TEST")
        msg.setField(self.codec.protocol.fixtags.HandlInst, "1")
        msg.setField(self.codec.protocol.fixtags.ExDestination, "XLON")
        msg.setField(self.codec.protocol.fixtags.Side, 1)
        msg.setField(self.codec.protocol.fixtags.ClOrdID, "abcdefg")
        msg.setField(self.codec.protocol.fixtags.Currency, "GBP")

        rptgrp1 = FIXContext()
        rptgrp1.setField("611", "aaa")
        rptgrp1.setField("612", "bbb")
        rptgrp1.setField("613", "ccc")

        msg.addRepeatingGroup("444", rptgrp1, 0)

        for i in range(0, 20):
            encoded = self.codec.pack(msg, mock_session)
            self.messages.append(self.codec.parse(encoded.encode('utf-8'))[0])
Пример #6
0
    def testEncode(self):
        from datetime import datetime

        print("%s" % (datetime.utcnow()))

        mock_session = mock.Mock()
        mock_session.senderCompId = "sender"
        mock_session.targetCompId = "target"
        mock_session.allocateSndSeqNo.return_value = 1

        protocol = importlib.import_module("pyfix.FIX44")
        codec = Codec(protocol)

        msg = FIXMessage(codec.protocol.msgtype.NEWORDERSINGLE)
        msg.setField(codec.protocol.fixtags.Price, "123.45")
        msg.setField(codec.protocol.fixtags.OrderQty, 9876)
        msg.setField(codec.protocol.fixtags.Symbol, "VOD.L")
        msg.setField(codec.protocol.fixtags.SecurityID, "GB00BH4HKS39")
        msg.setField(codec.protocol.fixtags.SecurityIDSource, "4")
        msg.setField(codec.protocol.fixtags.Symbol, "VOD.L")
        msg.setField(codec.protocol.fixtags.Account, "TEST")
        msg.setField(codec.protocol.fixtags.HandlInst, "1")
        msg.setField(codec.protocol.fixtags.ExDestination, "XLON")
        msg.setField(codec.protocol.fixtags.Side, 1)
        msg.setField(codec.protocol.fixtags.ClOrdID, "abcdefg")
        msg.setField(codec.protocol.fixtags.Currency, "GBP")

        rptgrp1 = FIXContext()
        rptgrp1.setField("611", "aaa")
        rptgrp1.setField("612", "bbb")
        rptgrp1.setField("613", "ccc")

        msg.addRepeatingGroup("444", rptgrp1, 0)

        rptgrp2 = FIXContext()
        rptgrp2.setField("611", "zzz")
        rptgrp2.setField("612", "yyy")
        rptgrp2.setField("613", "xxx")
        msg.addRepeatingGroup("444", rptgrp2, 1)

        result = codec.encode(msg, mock_session)
        expected = '8=FIX.4.4\x019=201\x0135=D\x0149=sender\x0156=target\x0134=1\x0152=20150619-11:08:54.000\x0144=123.45\x0138=9876\x0155=VOD.L\x0148=GB00BH4HKS39\x0122=4\x011=TEST\x0121=1\x01100=XLON\x0154=1\x0111=abcdefg\x0115=GBP\x01444=2\x01611=aaa\x01612=bbb\x01613=ccc\x01611=zzz\x01612=yyy\x01613=xxx\x0110=255\x01'
        self.assertEqual(expected, result)
Пример #7
0
    def testEncode(self):
        from datetime import datetime

        print("%s" % (datetime.utcnow()))

        mock_session = mock.Mock()
        mock_session.senderCompId = "sender"
        mock_session.targetCompId = "target"
        mock_session.allocateSndSeqNo.return_value = 1

        protocol = importlib.import_module("pyfix.FIX44")
        codec = Codec(protocol)

        msg = FIXMessage(codec.protocol.msgtype.NEWORDERSINGLE)
        msg.setField(codec.protocol.fixtags.Price, "123.45")
        msg.setField(codec.protocol.fixtags.OrderQty, 9876)
        msg.setField(codec.protocol.fixtags.Symbol, "VOD.L")
        msg.setField(codec.protocol.fixtags.SecurityID, "GB00BH4HKS39")
        msg.setField(codec.protocol.fixtags.SecurityIDSource, "4")
        msg.setField(codec.protocol.fixtags.Symbol, "VOD.L")
        msg.setField(codec.protocol.fixtags.Account, "TEST")
        msg.setField(codec.protocol.fixtags.HandlInst, "1")
        msg.setField(codec.protocol.fixtags.ExDestination, "XLON")
        msg.setField(codec.protocol.fixtags.Side, 1)
        msg.setField(codec.protocol.fixtags.ClOrdID, "abcdefg")
        msg.setField(codec.protocol.fixtags.Currency, "GBP")

        rptgrp1 = FIXContext()
        rptgrp1.setField("611", "aaa")
        rptgrp1.setField("612", "bbb")
        rptgrp1.setField("613", "ccc")

        msg.addRepeatingGroup("444", rptgrp1, 0)

        rptgrp2 = FIXContext()
        rptgrp2.setField("611", "zzz")
        rptgrp2.setField("612", "yyy")
        rptgrp2.setField("613", "xxx")
        msg.addRepeatingGroup("444", rptgrp2, 1)

        result = codec.encode(msg, mock_session)
        expected = '8=FIX.4.4\x019=201\x0135=D\x0149=sender\x0156=target\x0134=1\x0152=20150619-11:08:54.000\x0144=123.45\x0138=9876\x0155=VOD.L\x0148=GB00BH4HKS39\x0122=4\x011=TEST\x0121=1\x01100=XLON\x0154=1\x0111=abcdefg\x0115=GBP\x01444=2\x01611=aaa\x01612=bbb\x01613=ccc\x01611=zzz\x01612=yyy\x01613=xxx\x0110=255\x01'
        self.assertEqual(expected, result)
Пример #8
0
    def testMsgConstruction(self):
        msg = FIXMessage("AB")
        msg.setField("45", "dgd")
        msg.setField("32", "aaaa")
        msg.setField("323", "bbbb")

        rptgrp1 = FIXContext()
        rptgrp1.setField("611", "aaa")
        rptgrp1.setField("612", "bbb")
        rptgrp1.setField("613", "ccc")

        msg.addRepeatingGroup("444", rptgrp1, 0)

        rptgrp2 = FIXContext()
        rptgrp2.setField("611", "zzz")
        rptgrp2.setField("612", "yyy")
        rptgrp2.setField("613", "xxx")
        msg.addRepeatingGroup("444", rptgrp2, 1)

        self.assertEqual(
            "45=dgd|32=aaaa|323=bbbb|444=2=>[611=aaa|612=bbb|613=ccc, 611=zzz|612=yyy|613=xxx]",
            str(msg))

        msg.removeRepeatingGroupByIndex("444", 1)
        self.assertEqual(
            "45=dgd|32=aaaa|323=bbbb|444=1=>[611=aaa|612=bbb|613=ccc]",
            str(msg))

        msg.addRepeatingGroup("444", rptgrp2, 1)

        rptgrp3 = FIXContext()
        rptgrp3.setField("611", "ggg")
        rptgrp3.setField("612", "hhh")
        rptgrp3.setField("613", "jjj")
        rptgrp2.addRepeatingGroup("445", rptgrp3, 0)
        self.assertEqual(
            "45=dgd|32=aaaa|323=bbbb|444=2=>[611=aaa|612=bbb|613=ccc, 611=zzz|612=yyy|613=xxx|445=1=>[611=ggg|612=hhh|613=jjj]]",
            str(msg))

        grp = msg.getRepeatingGroupByTag("444", "612", "yyy")
        self.assertEqual(
            "611=zzz|612=yyy|613=xxx|445=1=>[611=ggg|612=hhh|613=jjj]",
            str(grp))
Пример #9
0
    def testMsgConstruction(self):
        msg = FIXMessage("AB")
        msg.setField("45", "dgd")
        msg.setField("32", "aaaa")
        msg.setField("323", "bbbb")

        rptgrp1 = FIXContext()
        rptgrp1.setField("611", "aaa")
        rptgrp1.setField("612", "bbb")
        rptgrp1.setField("613", "ccc")

        msg.addRepeatingGroup("444", rptgrp1, 0)

        rptgrp2 = FIXContext()
        rptgrp2.setField("611", "zzz")
        rptgrp2.setField("612", "yyy")
        rptgrp2.setField("613", "xxx")
        msg.addRepeatingGroup("444", rptgrp2, 1)

        self.assertEqual("45=dgd|32=aaaa|323=bbbb|444=2=>[611=aaa|612=bbb|613=ccc, 611=zzz|612=yyy|613=xxx]", str(msg))

        msg.removeRepeatingGroupByIndex("444", 1)
        self.assertEqual("45=dgd|32=aaaa|323=bbbb|444=1=>[611=aaa|612=bbb|613=ccc]", str(msg))

        msg.addRepeatingGroup("444", rptgrp2, 1)

        rptgrp3 = FIXContext()
        rptgrp3.setField("611", "ggg")
        rptgrp3.setField("612", "hhh")
        rptgrp3.setField("613", "jjj")
        rptgrp2.addRepeatingGroup("445", rptgrp3, 0)
        self.assertEqual("45=dgd|32=aaaa|323=bbbb|444=2=>[611=aaa|612=bbb|613=ccc, 611=zzz|612=yyy|613=xxx|445=1=>[611=ggg|612=hhh|613=jjj]]", str(msg))

        grp = msg.getRepeatingGroupByTag("444", "612", "yyy")
        self.assertEqual("611=zzz|612=yyy|613=xxx|445=1=>[611=ggg|612=hhh|613=jjj]", str(grp))