예제 #1
0
    def group(self, message: ReconMessage, attributes: tuple,  *args, **kwargs):
        message_type: str = message.proto_message.metadata.message_type

        if message_type in ['NewOrderSingle', 'OrderCancelRequest', 'OrderCancelReplaceRequest']:
            message.group_id = Group.REQUEST
        elif message_type in ['ExecutionReport', 'OrderCancelReject']:
            message.group_id = Group.RESPONSE
예제 #2
0
    def group(self, message: ReconMessage, attributes: tuple, *args, **kwargs):
        message_type: str = message.proto_message.metadata.message_type
        session_alias = message.proto_message.metadata.id.connection_id.session_alias
        direction = message.proto_message.metadata.id.direction
        if session_alias not in ['demo-conn1', 'demo-conn2'] or \
                message_type not in ['ExecutionReport']:
            return

        if message_type == 'ExecutionReport' and direction != Direction.FIRST:
            return

        if message_type == 'ExecutionReport' and message.proto_message.fields[
                'ExecType'].simple_value != 'F':
            return

        if message_type == 'ExecutionReport' and \
                message.proto_message.fields['TrdMatchID'].simple_value == "":
            logger.info(
                f"RULE '{self.get_name()}'. ER with empty TrdMatchID: {message.proto_message}."
            )
            return

        if session_alias in [
                'demo-conn1',
        ]:
            message.group_id = 'ER_FIX01'
        elif session_alias in ['demo-conn2']:
            message.group_id = 'ER_FIX02'
예제 #3
0
 def hash(self, message: ReconMessage, attributes: tuple):
     cl_ord_id = message.proto_message.fields['SecondaryClOrdID'].simple_value
     security_id = message.proto_message.fields['SecurityID'].simple_value
     val = ''
     for field_name in ['SecondaryClOrdID', 'SecurityID']:
         if message.proto_message.fields[field_name].simple_value == '':
             return
         val += message.proto_message.fields[field_name].simple_value
     message.hash = hash(val)
     message.hash_info['SecondaryClOrdID'] = cl_ord_id
     message.hash_info['SecurityID'] = security_id
 def hash(self, message: ReconMessage, attributes: tuple, *args, **kwargs):
     exec_type = message.proto_message.fields['ExecType'].simple_value
     cl_ord_id = message.proto_message.fields['ClOrdID'].simple_value
     exec_id = message.proto_message.fields['ExecID'].simple_value
     val = ''
     for field_name in ['ClOrdID', 'ExecType', 'ExecID']:
         if message.proto_message.fields[field_name].simple_value == '':
             return
         val += message.proto_message.fields[field_name].simple_value
     message.hash = hash(val)
     message.hash_info['ClOrdID'] = cl_ord_id
     message.hash_info['ExecType'] = exec_type
     message.hash_info['ExecID'] = exec_id
    def group(self, message: ReconMessage, attributes: tuple, *args, **kwargs):
        message_type: str = message.proto_message.metadata.message_type
        session_alias = message.proto_message.metadata.id.connection_id.session_alias
        direction = message.proto_message.metadata.id.direction
        if session_alias not in ['demo-conn1', 'demo-conn2', 'demo-dc1', 'demo-dc2'] or \
                message_type not in ['ExecutionReport']:
            return

        if message_type == 'ExecutionReport' and direction != Direction.FIRST:
            return

        if session_alias in ['demo-conn1', 'demo-conn2']:
            message.group_id = 'ER_FIX'
        elif session_alias in ['demo-dc1', 'demo-dc2']:
            message.group_id = 'ER_DC'
    def group(self, message: ReconMessage, attributes: tuple):
        message_type: str = message.proto_message.metadata.message_type
        session_alias = message.proto_message.metadata.id.connection_id.session_alias
        if message_type not in ['ExecutionReport', 'NewOrderSingle'] or \
                session_alias not in ['arfq01fix04', 'arfq01dc04']:
            return

        message.group_id = message_type.translate({ord(c): '' for c in string.ascii_lowercase})
        message.group_id += '_' + session_alias
        message.group_info['session_alias'] = session_alias

        if message_type == 'ExecutionReport':
            exec_type = message.proto_message.fields['ExecType'].simple_value
            message.group_id += '_' + exec_type
            message.group_info['ExecType'] = exec_type
예제 #7
0
    def group(self, message: ReconMessage, attributes: tuple):
        message_type: str = message.proto_message.metadata.message_type
        session_alias = message.proto_message.metadata.id.connection_id.session_alias
        direction = message.proto_message.metadata.id.direction
        if session_alias not in ['demo-conn1', 'demo-conn2', 'demo_log.txt'] or \
                message_type not in ['NewOrderSingle']:
            return

        if message_type == 'NewOrderSingle' and \
                message.proto_message.fields['SecondaryClOrdID'].simple_value == "":
            logger.info(f"RULE '{self.get_name()}'. NOS with empty SecondaryClOrdID: {message.proto_message}.")
            return

        if session_alias in ['demo-conn1', 'demo-conn2']:
            message.group_id = 'NOS_CONN'
        elif session_alias in ['demo_log.txt']:
            message.group_id = 'NOS_LOG'
예제 #8
0
    def group(self, message: ReconMessage, attributes: tuple):
        message_type: str = message.proto_message.metadata.message_type
        session_alias = message.proto_message.metadata.id.connection_id.session_alias
        direction = message.proto_message.metadata.id.direction
        if session_alias not in ['demo-conn1', 'security_status.txt'] or \
                message_type not in ['SecurityStatus']:
            return

        if message_type == 'SecurityStatus' and \
                message.proto_message.fields['SecurityStatusReqID'].simple_value == "":
            logger.info(
                f"RULE '{self.get_name()}'. SS with empty SecurityStatusReqID: {message.proto_message}."
            )
            return

        if session_alias in ['demo-conn1', 'demo-conn2']:
            message.group_id = 'SS_CONN'
        elif session_alias in ['security_status.txt']:
            message.group_id = 'SS_LOG'
    def group(self, message: ReconMessage, attributes: tuple):
        message_type: str = message.proto_message.metadata.message_type
        session_alias = message.proto_message.metadata.id.connection_id.session_alias
        direction = message.proto_message.metadata.id.direction
        if session_alias not in self.config.keys() or message_type not in [
                'ExecutionReport'
        ]:
            return

        if message_type == 'ExecutionReport' and direction != Direction.FIRST:
            return

        message.group_id = self.config[session_alias]
    def group(self, message: ReconMessage, attributes: tuple):
        message_type: str = message.proto_message.metadata.message_type
        session_alias = message.proto_message.metadata.id.connection_id.session_alias
        direction = message.proto_message.metadata.id.direction
        if session_alias not in self.config.keys() or message_type not in [
                'NewOrderSingle'
        ]:
            return

        if message_type == 'NewOrderSingle' and \
                message.proto_message.fields['SecondaryClOrdID'].simple_value == "":
            logger.info(
                f"RULE '{self.get_name()}'. NOS with empty SecondaryClOrdID: {message.proto_message}."
            )
            return

        message.group_id = self.config[session_alias]
예제 #11
0
    def group(self, message: ReconMessage, attributes: tuple):
        message_type: str = message.proto_message.metadata.message_type
        session_alias = message.proto_message.metadata.id.connection_id.session_alias
        direction = message.proto_message.metadata.id.direction
        if session_alias not in self.config.keys():
            return

        if message_type == 'ExecutionReport' and direction != Direction.FIRST \
                and message.proto_message.fields['ExecType'].simple_value != 'F':
            return

        if message_type == 'ExecutionReport' and \
                message.proto_message.fields['TrdMatchID'].simple_value == "":
            logger.info(
                f"RULE '{self.get_name()}'. ER with empty TrdMatchID: {message.proto_message}."
            )
            return

        message.group_id = self.config[session_alias]
예제 #12
0
    def submitGroupBatch(self, request, context):
        try:
            logger.debug(
                f'submitGroupBatch request: {MessageToString(request, as_one_line=True)}'
            )

            messages = [
                message.message for group in request.groups
                for message in group.messages if message.HasField('message')
            ]

            for proto_message in messages:
                message = ReconMessage(proto_message=proto_message)

                for rule in self._rules:

                    process_timer = rule.RULE_PROCESSING_TIME
                    start_time = time.time()

                    try:
                        rule.process((), message)
                    except Exception:
                        logger.exception(
                            f'Rule: {rule.get_name()}. '
                            f'An error occurred while processing the message. '
                            f'Message: {MessageToString(proto_message, as_one_line=True)}'
                        )
                    finally:
                        process_timer.observe(time.time() - start_time)

                logger.debug(
                    f"Processed '{proto_message.metadata.message_type}' "
                    f"id='{MessageUtils.str_message_id(proto_message)}'")

            return RequestStatus(status=RequestStatus.SUCCESS,
                                 message='Successfully processed batch')
        except Exception as e:
            logger.exception('submitGroupBatch request failed')
            return RequestStatus(status=RequestStatus.ERROR, message=str(e))
예제 #13
0
    def handler(self, attributes: tuple, batch: MessageBatch):
        try:
            for proto_message in batch.messages:
                message = ReconMessage(proto_message=proto_message)

                process_timer = self._rule.RULE_PROCESSING_TIME
                start_time = time.time()

                self._rule.process(message, attributes)

                process_timer.observe(time.time() - start_time)

                logger.debug("Processed '%s' id='%s'",
                             proto_message.metadata.message_type,
                             MessageUtils.str_message_id(proto_message))

            logger.debug("Cache size '%s': %s.", self._rule.get_name(),
                         self._rule.log_groups_size())
        except Exception:
            logger.exception(
                f'Rule: {self._rule.get_name()}. '
                f'An error occurred while processing the received message. '
                f'Message: {MessageToString(batch, as_one_line=True)}')
예제 #14
0
 def hash(self, message: ReconMessage, attributes: tuple, *args, **kwargs):
     trd_match_id = message.proto_message.fields['TrdMatchID'].simple_value
     message.hash = hash(
         message.proto_message.fields['TrdMatchID'].simple_value)
     message.hash_info['TrdMatchID'] = trd_match_id
예제 #15
0
 def hash(self, message: ReconMessage, attributes: tuple):
     trd_match_id = message.proto_message.fields[
         'SecurityStatusReqID'].simple_value
     message.hash = hash(
         message.proto_message.fields['SecurityStatusReqID'].simple_value)
     message.hash_info['SecurityStatusReqID'] = trd_match_id
 def hash(self, message: ReconMessage, attributes: tuple):
     cl_ord_id = message.proto_message.fields['ClOrdID'].simple_value
     message.hash = hash(message.proto_message.fields['ClOrdID'].simple_value)
     message.hash_info['ClOrdID'] = cl_ord_id