def run(self) -> None: logger.info( "Starting OrderDataStream {0}".format(self.stream_id), extra={ "stream_id": self.stream_id, "customer_strategy_refs": config.customer_strategy_ref, "conflate_ms": self.conflate_ms, "streaming_timeout": self.streaming_timeout, }, ) self._stream = self.betting_client.streaming.create_stream( unique_id=self.stream_id, listener=self._listener) try: self.stream_id = self._stream.subscribe_to_orders( order_filter=filters.streaming_order_filter( customer_strategy_refs=[config.customer_strategy_ref] if config.customer_strategy_ref else None, partition_matched_by_strategy_ref=True, include_overall_position=False, ), conflate_ms=self.conflate_ms, ) self._stream.start() except BetfairError: logger.error("OrderDataStream {0} run error".format( self.stream_id), exc_info=True) raise except Exception: logger.critical("OrderDataStream {0} run error".format( self.stream_id), exc_info=True) raise logger.info("Stopped OrderDataStream {0}".format(self.stream_id))
def run(self) -> None: logger.info("Starting OrderStream") if not self._output_thread.is_alive(): logger.info("Starting output_thread {0}".format( self._output_thread)) self._output_thread.start() self._stream = self.betting_client.streaming.create_stream( unique_id=self.stream_id, listener=self._listener) try: self.stream_id = self._stream.subscribe_to_orders( order_filter=filters.streaming_order_filter( customer_strategy_refs=[config.hostname], partition_matched_by_strategy_ref=True, include_overall_position=False, ), conflate_ms=self.conflate_ms, ) self._stream.start() except BetfairError: logger.error("OrderStream run error", exc_info=True) raise except Exception: logger.critical("OrderStream run error", exc_info=True) raise logger.info("Stopped OrderStream {0}".format(self.stream_id))
def __init__( self, client: APIClient, logger: Logger, message_handler, partition_matched_by_strategy_ref=True, include_overall_position=None, customer_strategy_refs=None, **kwargs, ): super().__init__( client=client, logger_adapter=LoggerAdapter("BetfairOrderStreamClient", logger), message_handler=message_handler, **kwargs, ) self.order_filter = streaming_order_filter( include_overall_position=include_overall_position, customer_strategy_refs=customer_strategy_refs, partition_matched_by_strategy_ref=partition_matched_by_strategy_ref, )
def test_streaming_order_filter(self): response = streaming_order_filter() assert response == {} response = streaming_order_filter(include_overall_position=True) assert response == {"includeOverallPosition": True}