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))
def test_can_modify_order(self): # Arrange strategy = TradingStrategy(order_id_tag='001') self.exec_engine.register_strategy(strategy) order = strategy.order_factory.limit(USDJPY_FXCM, OrderSide.BUY, Quantity(100000), Price(90.001, 3)) strategy.submit_order(order, strategy.position_id_generator.generate()) # Act strategy.modify_order(order, Quantity(110000), Price(90.002, 3)) # Assert self.assertEqual(order, strategy.orders()[order.id]) self.assertEqual(OrderState.WORKING, strategy.orders()[order.id].state) self.assertEqual(Quantity(110000), strategy.orders()[order.id].quantity) self.assertEqual(Price(90.002, 3), strategy.orders()[order.id].price) self.assertTrue(strategy.is_flat()) self.assertTrue(strategy.order_exists(order.id)) self.assertTrue(strategy.is_order_working(order.id)) self.assertFalse(strategy.is_order_completed(order.id))