예제 #1
0
    async def test_search_detailed_contracts(self):
        """Test function `search_detailed_contracts`."""
        contract = sample_contracts.us_future()
        contract.lastTradeDateOrContractMonth = ''

        res = await self._bridge.search_detailed_contracts(contract=contract)
        self.assertGreater(len(res), 1)
        for item in res:
            print(item.contract)
예제 #2
0
    async def test_resolve_head_timestamp(self):
        """Test function `resolve_head_timestamp`."""
        head_timestamp = await self._client.resolve_head_timestamp(
            req_id=Const.RID_RESOLVE_HEAD_TIMESTAMP.value,
            contract=sample_contracts.us_future(),
            show=dt.EarliestDataPoint.BID)

        print(head_timestamp)

        self.assertIsNotNone(head_timestamp)
        self.assertIsInstance(head_timestamp, int)
예제 #3
0
    async def test_resolve_contracts(self):
        """Test function `resolve_contracts`."""
        contract: ib_contract.Contract = sample_contracts.us_future()
        contract.lastTradeDateOrContractMonth = ''

        res: List[ib_contract.ContractDetails] = await self._client\
            .resolve_contracts(req_id=Const.RID_RESOLVE_CONTRACTS.value,
                               contract=contract)

        self.assertTrue(res)
        self.assertGreater(len(res), 1)
예제 #4
0
    async def test_req_historical_ticks_2(self):
        """Test function `req_historical_ticks`.

        * Reqest tick data for `TRADES`.
        """
        async for result in self._bridge.req_historical_ticks(
                contract=sample_contracts.us_future(),
                start=self._start,
                end=self._end,
                tick_type=datatype.HistoricalTicks.TRADES,
                retry=0):
            self.assertTrue(result.ticks)
            self.assertIsInstance(result.ticks[0], wrapper.HistoricalTickLast)
예제 #5
0
    async def test_req_historical_ticks_2(self):
        """Test function `req_historical_ticks`.

        * Request tick data for `MidPoint`.
        """
        result = await self._client.req_historical_ticks(
            req_id=self._req_id,
            contract=sample_contracts.us_future(),
            start_date_time=self._start.replace(tzinfo=None),
            show=datatype.HistoricalTicks.TRADES)

        self.assertTrue(result)
        self.assertIsInstance(result, list)
        self.assertIsInstance(result[0], wrapper.HistoricalTickLast)
예제 #6
0
    async def test_tick_by_tick_all_last_0(self):
        """Test overridden function `tickByTickAllLast` with tick type `Last`.
        """
        self._client.reqTickByTickData(
            reqId=self._req_id, contract=sample_contracts.us_future(),
            tickType=datatype.LiveTicks.LAST.value, numberOfTicks=0,
            ignoreSize=True
        )

        async for elem in self._queue.stream():
            if elem is fq.Status.FINISHED:
                continue # Let the async task finish
            if not self._received:
                # Expect `HistoricalTickLast` to be sent to queue
                self.assertIsInstance(elem, wrapper.HistoricalTickLast)
                await self._stop_streaming(req_id=self._req_id)
예제 #7
0
    async def test_stream_live_ticks_3(self):
        """Test function `stream_live_ticks`.

        * Request tick data for `LAST`.
        """
        req_id = await self._bridge.stream_live_ticks(
            contract=sample_contracts.us_future(),
            listener=self._listener,
            tick_type=datatype.LiveTicks.LAST)

        while not self._listener.ticks:
            await asyncio.sleep(0.5)

        self.assertIsInstance(self._listener.ticks[0],
                              wrapper.HistoricalTickLast)

        self._bridge._client.cancel_live_ticks_stream(req_id)
        await asyncio.sleep(0.5)
예제 #8
0
    async def test_tick_by_tick_all_last(self):
        """Test overridden function `tickByTickAllLast`."""
        f_queue = self._wrapper.get_request_queue(
            req_id=Const.RID_REQ_TICK_BY_TICK_DATA_ALL_LAST)

        self._client.reqTickByTickData(
            reqId=Const.RID_REQ_TICK_BY_TICK_DATA_ALL_LAST.value,
            contract=sample_contracts.us_future(),
            tickType='AllLast',
            numberOfTicks=0,
            ignoreSize=True)

        async for ele in f_queue.stream():
            self.assertIsInstance(ele,
                                  (ib_wrapper.HistoricalTickLast, fq._Status))
            self.assertIsNot(ele, fq._Status.ERROR)

            if ele is not fq._Status.FINISHED:
                self._client.cancelTickByTickData(
                    reqId=Const.RID_REQ_TICK_BY_TICK_DATA_ALL_LAST.value)

                f_queue.put(element=fq._Status.FINISHED)