Ejemplo n.º 1
0
    def test_can_cancel_all_orders(self):
        # Arrange
        strategy = TradingStrategy(order_id_tag='001')
        self.exec_engine.register_strategy(strategy)

        order1 = strategy.order_factory.stop(USDJPY_FXCM, OrderSide.BUY,
                                             Quantity(100000),
                                             Price(90.003, 3))

        order2 = strategy.order_factory.stop(USDJPY_FXCM, OrderSide.BUY,
                                             Quantity(100000),
                                             Price(90.005, 3))

        position_id = strategy.position_id_generator.generate()

        strategy.submit_order(order1, position_id)
        strategy.submit_order(order2, position_id)

        # Act
        strategy.cancel_all_orders()

        # Assert
        self.assertEqual(order1, strategy.orders()[order1.id])
        self.assertEqual(order2, strategy.orders()[order2.id])
        self.assertEqual(OrderState.CANCELLED,
                         strategy.orders()[order1.id].state)
        self.assertEqual(OrderState.CANCELLED,
                         strategy.orders()[order2.id].state)
        self.assertTrue(order1.id in strategy.orders_completed())
        self.assertTrue(order2.id in strategy.orders_completed())
Ejemplo n.º 2
0
    def test_strategy_can_submit_order(self):
        # Arrange
        strategy = TradingStrategy(order_id_tag='001')
        self.exec_engine.register_strategy(strategy)

        order = strategy.order_factory.market(USDJPY_FXCM, OrderSide.BUY,
                                              Quantity(100000))

        # Act
        strategy.submit_order(order, strategy.position_id_generator.generate())

        # Assert
        self.assertEqual(order, strategy.orders()[order.id])
        self.assertEqual(OrderState.FILLED, strategy.orders()[order.id].state)
        self.assertTrue(order.id not in strategy.orders_working())
        self.assertTrue(order.id in strategy.orders_completed())
        self.assertTrue(strategy.order_exists(order.id))
        self.assertFalse(strategy.is_order_working(order.id))
        self.assertTrue(strategy.is_order_completed(order.id))