Beispiel #1
0
    def test_checkIsInMessage(self):
        self.object.setVersion(fix.BeginString_FIX40)
        self.object.addField(fix.BeginString().getTag())
        self.object.addField(fix.BodyLength().getTag())
        self.object.addField(fix.MsgType().getTag())
        self.object.addField(fix.CheckSum().getTag())
        self.object.addField(fix.TestReqID().getTag())
        self.object.addField(fix.Symbol().getTag())
        self.object.addMsgType(fix.MsgType_TestRequest)
        self.object.addMsgField(fix.MsgType_TestRequest,
                                fix.TestReqID().getTag())

        testReqID = fix.TestReqID("1")

        message = fix40.TestRequest()
        message.setField(testReqID)
        try:
            self.object.validate(message)
            self.failUnless(1)
        except fix.Exception as e:
            self.failUnless(0)

        message.setField(fix.Symbol("MSFT"))
        try:
            self.object.validate(message)
            self.failUnless(0)
        except fix.Exception as e:
            self.failUnless(1)
Beispiel #2
0
    def test_checkHasRequired(self):
        self.object.setVersion(fix.BeginString_FIX40)
        self.object.addField(fix.BeginString().getTag())
        self.object.addField(fix.BodyLength().getTag())
        self.object.addField(fix.MsgType().getTag())
        self.object.addField(fix.SenderCompID().getTag())
        self.object.addField(fix.TargetCompID().getTag())
        self.object.addHeaderField(fix.SenderCompID().getTag(), True)
        self.object.addHeaderField(fix.TargetCompID().getTag(), False)
        self.object.addField(fix.CheckSum().getTag())
        self.object.addField(fix.TestReqID().getTag())
        self.object.addMsgType(fix.MsgType_TestRequest)
        self.object.addMsgField(fix.MsgType_TestRequest,
                                fix.TestReqID().getTag())
        self.object.addRequiredField(fix.MsgType_TestRequest,
                                     fix.TestReqID().getTag())

        message = fix40.TestRequest()
        try:
            self.object.validate(message)
            self.failUnless(0)
        except fix.Exception as e:
            self.failUnless(1)

        message.getHeader().setField(fix.SenderCompID("SENDER"))
        try:
            self.object.validate(message)
            self.failUnless(0)
        except fix.Exception as e:
            self.failUnless(1)

        message.setField(fix.TestReqID("1"))
        try:
            self.object.validate(message)
            self.failUnless(1)
        except fix.Exception as e:
            self.failUnless(0)

        message.getHeader().removeField(fix.SenderCompID().getTag())
        message.setField(fix.SenderCompID("SENDER"))
        try:
            self.object.validate(message)
            self.failUnless(0)
        except fix.Exception as e:
            self.failUnless(1)
Beispiel #3
0
    def test_checkValidTagNumber(self):
        self.object.setVersion(fix.BeginString_FIX40)
        self.object.addField(fix.BeginString().getTag())
        self.object.addField(fix.BodyLength().getTag())
        self.object.addField(fix.MsgType().getTag())
        self.object.addField(fix.CheckSum().getTag())
        self.object.addField(fix.TestReqID().getTag())
        self.object.addMsgType(fix.MsgType_TestRequest)
        self.object.addMsgField(fix.MsgType_TestRequest,
                                fix.TestReqID().getTag())

        testReqID = fix.TestReqID("1")
        message = fix40.TestRequest()
        message.setField(testReqID)
        message.setField(TooHigh("value"))

        try:
            self.object.validate(message)
            self.failUnless(0)
        except fix.Exception as e:
            self.failUnless(1)

        self.object.addField(501)
        self.object.addMsgField(fix.MsgType_TestRequest, 501)
        try:
            self.object.validate(message)
            self.failUnless(1)
        except fix.Exception as e:
            self.failUnless(0)

        message.setField(5000, "value")
        try:
            self.object.validate(message)
            self.failUnless(0)
        except fix.Exception as e:
            self.failUnless(1)

        self.object.checkUserDefinedFields(False)
        try:
            self.object.validate(message)
            self.failUnless(1)
        except fix.Exception as e:
            self.failUnless(0)
    def test_checkHasRequired(self):
        self.object.setVersion(fix.BeginString_FIX40)
        self.object.addField(fix.BeginString().getField())
        self.object.addField(fix.BodyLength().getField())
        self.object.addField(fix.MsgType().getField())
        self.object.addField(fix.SenderCompID().getField())
        self.object.addField(fix.TargetCompID().getField())
        self.object.addHeaderField(fix.SenderCompID().getField(), 1)
        self.object.addHeaderField(fix.TargetCompID().getField(), 0)
        self.object.addField(fix.CheckSum().getField())
        self.object.addField(fix.TestReqID().getField())
        self.object.addMsgType(fix.MsgType_TestRequest)
        self.object.addMsgField(fix.MsgType_TestRequest,
                                fix.TestReqID().getField())
        self.object.addRequiredField(fix.MsgType_TestRequest,
                                     fix.TestReqID().getField())

        message = fix40.TestRequest()
        try:
            self.object.validate(message)
            self.failUnless(0)
        except fix.Exception, e:
            self.failUnless(1)
Beispiel #5
0
    storeFactory = fix.FileStoreFactory(settings)
    logFactory = fix.FileLogFactory(settings)
    initiator = fix.SocketInitiator(application, storeFactory, settings,
                                    logFactory)
    message_flag = True
    initiator.start()
    while 1:
        time.sleep(1)
        if message_flag is True:

            message = fix.Message()
            header = message.getHeader()
            trailer = message.getTrailer()

            header.setField(fix.BeginString(fix.BeginString_FIX42))
            header.setField(fix.BodyLength())
            header.setField(fix.MsgType(fix.MsgType_NewOrderSingle))
            header.setField(fix.SendingTime())
            header.setField(fix.SenderSubID("SG1"))
            header.setField(fix.TargetSubID("BARCA"))
            header.setField(fix.MsgSeqNum())
            header.setField(fix.DefaultApplVerID(fix.ApplVerID_FIX42))
            message.setField(fix.ClOrdID("ClOrdID"))
            message.setField(
                fix.AccountType(
                    fix.
                    AccountType_ACCOUNT_IS_CARRIED_ON_CUSTOMER_SIDE_OF_BOOKS))
            message.setField(fix.Symbol("APPL"))
            message.setField(
                fix.HandlInst(
                    fix.
Beispiel #6
0
parser_handler = logging.handlers.RotatingFileHandler(
    filename="./log/parser.log",
    mode="a",
    maxBytes=5 * 1024 * 1024,
    backupCount=50)
fmt = logging.Formatter("%(asctime)s.%(msecs)03d %(message)s")
parser_handler.setFormatter(fmt)
parser_handler.setLevel(logging.DEBUG)
_parser_logger = logging.getLogger("mega_trader.mt_data_parser")
_parser_logger.propagate = False
_parser_logger.addHandler(parser_handler)

dd = fix.DataDictionary(definitions.FIX50SP02)

begin_string = fix.BeginString()
body_length = fix.BodyLength()
message_type = fix.MsgType()
sender_id = fix.SenderCompID()
target_id = fix.TargetCompID()
msg_seq = fix.MsgSeqNum()
sender_sub_id = fix.SenderSubID()
target_sub_id = fix.TargetSubID()
duplicate_flag = fix.PossDupFlag()
user_req_type = fix.UserRequestType()
gateway_id = fix.MarketID()
orig_sending_time = fix.OrigSendingTime()
sending_time = fix.SendingTime()
on_behalf_id = fix.OnBehalfOfCompID()
check_sum = fix.CheckSum()

TOKEN_NO = 48