Пример #1
0
    async def test_place_orders(self):
        """Test function `place_orders`."""
        # Prepare orders
        order1 = sample_orders.mkt(order_id=await self._bridge.next_order_id(),
                                   action=datatype.OrderAction.BUY)
        order2 = sample_orders.mkt(order_id=order1.orderId + 1,
                                   action=datatype.OrderAction.SELL)

        await self._bridge.place_orders(contract=sample_contracts.gbp_usd_fx(),
                                        orders=[order1, order2])
        self.assertTrue(order1.orderId in self._orders_manager.open_orders)
        self.assertTrue(order2.orderId in self._orders_manager.open_orders)
        self.assertFalse(
            self._orders_manager.is_pending_order(order_id=order1.orderId))
        self.assertFalse(
            self._orders_manager.is_pending_order(order_id=order2.orderId))
Пример #2
0
    async def test_place_orders_err(self):
        """Test function `place_orders`.

        * Error expected due to duplicate order ID.
        """
        # Prepare orders
        order1 = sample_orders.mkt(order_id=await self._bridge.next_order_id(),
                                   action=datatype.OrderAction.BUY)
        order2 = sample_orders.mkt(order_id=order1.orderId,
                                   action=datatype.OrderAction.SELL)

        with self.assertRaises(error.IBError):
            await self._bridge.place_orders(
                contract=sample_contracts.gbp_usd_fx(),
                orders=[order1, order2])
        self.assertFalse(
            self._orders_manager.is_pending_order(order_id=order1.orderId))
Пример #3
0
    async def test_submit_order(self):
        """Test function `submit_order`."""
        order_id = await self._client.req_next_order_id()

        await self._client.submit_order(contract=sample_contracts.gbp_usd_fx(),
                                        order=sample_orders.mkt(
                                            order_id=order_id,
                                            action=datatype.OrderAction.BUY))
        self.assertTrue(order_id in self._orders_manager.open_orders)
Пример #4
0
    async def test_submit_order_err(self):
        """Test function `submit_order`.

        * Error returned from IB for duplicated order ID.
        """
        with self.assertRaises(error.IBError):
            await self._client.submit_order(
                contract=sample_contracts.gbp_usd_fx(),
                order=sample_orders.mkt(order_id=1,
                                        action=datatype.OrderAction.BUY))
Пример #5
0
    async def test_order_status(self):
        """Test overridden function `orderStatus`."""
        order_id = await self._client.req_next_order_id()
        self._client.placeOrder(
            orderId=order_id, contract=sample_contracts.gbp_usd_fx(),
            order=sample_orders.mkt(order_id=order_id,
                                    action=datatype.OrderAction.SELL)
        )
        await asyncio.sleep(1)

        self.assertTrue(self._orders_manager.open_orders[order_id].exec_rec)
Пример #6
0
    async def test_open_order(self):
        """Test overridden function `openOrder`."""
        order_id = await self._client.req_next_order_id()
        self._client.placeOrder(
            orderId=order_id, contract=sample_contracts.gbp_usd_fx(),
            order=sample_orders.mkt(order_id=order_id,
                                    action=datatype.OrderAction.BUY)
        )
        await asyncio.sleep(1)

        self.assertTrue(order_id in self._orders_manager.open_orders)