async def test_cancel_live_ticks_stream(self):
        """Test function `cancel_live_ticks_stream`."""
        async def cancel_req():
            await asyncio.sleep(3)
            self._client.cancel_live_ticks_stream(
                req_id=Const.RID_CANCEL_LIVE_TICKS_STREAM.value)

        listener = utils.MockLiveTicksListener()

        stream = asyncio.create_task(
            self._client.stream_live_ticks(
                req_id=Const.RID_CANCEL_LIVE_TICKS_STREAM.value,
                contract=sample_contracts.gbp_usd_fx(),
                listener=listener,
                tick_type=dt.LiveTicks.BID_ASK))
        cancel = asyncio.create_task(cancel_req())

        try:
            await stream
            await cancel
        except error.IBError as err:
            tasks = asyncio.all_tasks()
            for task in tasks:
                task.cancel()

            raise err

        self.assertTrue(listener.finished)
    async def test_stream_live_ticks(self):
        """Test function `stream_live_ticks`."""
        async def cancel_req():
            await asyncio.sleep(5)
            self._client.cancelTickByTickData(
                reqId=Const.RID_STREAM_LIVE_TICKS.value)

            queue = self._wrapper.get_request_queue_no_throw(
                req_id=Const.RID_STREAM_LIVE_TICKS)
            queue.put(element=fq._Status.FINISHED)

        listener = utils.MockLiveTicksListener()

        stream = asyncio.create_task(
            self._client.stream_live_ticks(
                req_id=Const.RID_STREAM_LIVE_TICKS.value,
                contract=sample_contracts.gbp_usd_fx(),
                listener=listener,
                tick_type=dt.LiveTicks.BID_ASK))
        cancel = asyncio.create_task(cancel_req())

        try:
            await stream
            await cancel
        except error.IBError as err:
            tasks = asyncio.all_tasks()
            for task in tasks:
                task.cancel()

            raise err

        self.assertTrue(listener.ticks)
        self.assertTrue(listener.finished)
    async def test_stop_live_ticks_stream(self):
        """Test functions `stop_live_ticks_stream`."""
        listener = utils.MockLiveTicksListener()

        stream_id = await self._bridge.stream_live_ticks(
            contract=sample_contracts.gbp_usd_fx(),
            listener=listener, tick_type=dt.LiveTicks.BID_ASK
        )

        await asyncio.sleep(2)
        self._bridge.stop_live_ticks_stream(stream_id=stream_id)
        await asyncio.sleep(0.5)
        self.assertTrue(listener.finished)
    async def test_stream_live_ticks(self):
        """Test function `stream_live_ticks`."""
        client: ibpy_client._IBClient = self._bridge._client
        listener = utils.MockLiveTicksListener()

        req_id = await self._bridge.stream_live_ticks(
            contract=sample_contracts.gbp_usd_fx(),
            listener=listener, tick_type=dt.LiveTicks.BID_ASK
        )
        self.assertIsNotNone(req_id)

        await asyncio.sleep(5)
        self.assertTrue(listener.ticks)
        client.cancel_live_ticks_stream(req_id=req_id)
        await asyncio.sleep(0.5)
Beispiel #5
0
 def setUp(self):
     self._listener = utils.MockLiveTicksListener()
Beispiel #6
0
 def setUp(self):
     self._req_id = self._wrapper.next_req_id
     self._listener = utils.MockLiveTicksListener()