Beispiel #1
0
    async def on_receive(self, message: FIXMessage) -> FIXMessage:
        """
        Calls the relevant on_<message_type> handler for this type of message, or 'on_unhandled' if no
        handler has been defined.

        :param message: The message to process
        :return: The result after processing the on_<message_type> method.
        :raises: MessageProcessingError if the handler does not return a valid FIX message.
        """
        handler = self.type_handlers.get(message.type, self.on_unhandled)
        message = await handler(message)

        if message is None:
            raise MessageProcessingError(
                f"{self.name}: message handler '{handler.__name__}' did not provide a message to propagate "
                f"further up the pipeline. Perhaps you forgot to return a message instance in "
                f"{self.__module__}.{self.__class__.__name__}.{handler.__name__}?"
            )

        return message
Beispiel #2
0
 async def on_receive(self, data: bytes) -> FIXMessage:
     try:
         return self.decode_message(data)
     except Exception as e:
         raise MessageProcessingError() from e