def test_update_status_with_diff_cl_ord_id(self): order = Order( ModelFactory.build_order_state_from_nos( ModelFactory.build_new_order_request(timestamp=0, cl_id='TestClient', cl_ord_id="3", portf_id="TestPortf", broker_id="TestBroker", inst_id="HSI@SEHK", action=Buy, type=Limit, qty=1000, limit_price=18.5))) self.assertEquals(New, order.status()) status_update = ModelFactory.build_order_status_update( timestamp=0, broker_id="TestBroker", broker_event_id="3", broker_ord_id="3", cl_id='TestClient', cl_ord_id="ERROR", status=Submitted) with self.assertRaises(Exception) as ex: order.on_ord_upd(status_update)
def test_update_status_with_diff_ord_id(self): order = Order( NewOrderRequest(cl_id='test', cl_ord_id=1, inst_id=1, action=OrdAction.BUY, type=OrdType.LIMIT, qty=1000, limit_price=18.5)) self.assertEquals(OrdStatus.NEW, order.status) status_update = OrderStatusUpdate(cl_id='test', cl_ord_id=1, ord_id=2, inst_id=1, status=OrdStatus.SUBMITTED) order.on_ord_upd(status_update) status_update = OrderStatusUpdate(cl_id='test', cl_ord_id=1, ord_id=3, inst_id=1, status=OrdStatus.SUBMITTED) with self.assertRaises(Exception) as ex: order.on_ord_upd(status_update)
def test_on_ord_upd(self): order = Order( ModelFactory.build_order_state_from_nos( ModelFactory.build_new_order_request(timestamp=0, cl_id='TestClient', cl_ord_id="3", portf_id="TestPortf", broker_id="TestBroker", inst_id="HSI@SEHK", action=Buy, type=Limit, qty=1000, limit_price=18.5))) status_update = ModelFactory.build_order_status_update( timestamp=0, broker_id="TestBroker", broker_event_id="3", broker_ord_id="3", cl_id='TestClient', cl_ord_id="3", status=Submitted) order.on_ord_upd(status_update) self.assertEqual(status_update.broker_ord_id, order.broker_ord_id()) self.assertEquals(Submitted, order.status())
def test_update_status_with_diff_cl_ord_id(self): order = Order( NewOrderRequest(cl_id='test', cl_ord_id=1, inst_id=1, action=OrdAction.BUY, type=OrdType.LIMIT, qty=1000, limit_price=18.5)) self.assertEquals(OrdStatus.NEW, order.status) status_update = OrderStatusUpdate(cl_id='test', cl_ord_id=2, ord_id=2, inst_id=1, status=OrdStatus.SUBMITTED) with self.assertRaises(Exception) as ex: order.on_ord_upd(status_update)
def test_on_ord_upd(self): order = Order( NewOrderRequest(cl_id='test', cl_ord_id=1, inst_id=1, action=OrdAction.BUY, type=OrdType.LIMIT, qty=1000, limit_price=18.5)) self.assertEquals(OrdStatus.NEW, order.status) status_update = OrderStatusUpdate(cl_id='test', cl_ord_id=1, ord_id=1, inst_id=1, status=OrdStatus.SUBMITTED) order.on_ord_upd(status_update) self.assertEqual(status_update.ord_id, order.broker_ord_id) self.assertEquals(OrdStatus.SUBMITTED, order.status)
def test_is_done(self): order = Order( NewOrderRequest(cl_id='test', cl_ord_id=1, inst_id=1, action=OrdAction.BUY, type=OrdType.LIMIT, qty=1000, limit_price=18.5)) self.assertFalse(order.is_done()) status_update1 = OrderStatusUpdate(cl_id='test', cl_ord_id=1, ord_id=1, inst_id=1, status=OrdStatus.REJECTED) order.on_ord_upd(status_update1) self.assertTrue(order.is_done()) order2 = Order( NewOrderRequest(cl_id='test', cl_ord_id=2, inst_id=1, action=OrdAction.BUY, type=OrdType.LIMIT, qty=1000, limit_price=18.5)) status_update2 = OrderStatusUpdate(cl_id='test', cl_ord_id=2, ord_id=2, inst_id=1, status=OrdStatus.CANCELLED) order2.on_ord_upd(status_update2) self.assertTrue(order2.is_done()) order3 = Order( NewOrderRequest(cl_id='test', cl_ord_id=3, inst_id=1, action=OrdAction.BUY, type=OrdType.LIMIT, qty=1000, limit_price=18.5)) status_update3 = OrderStatusUpdate(cl_id='test', cl_ord_id=3, ord_id=3, inst_id=1, status=OrdStatus.FILLED) order3.on_ord_upd(status_update3) self.assertTrue(order3.is_done())
def test_is_done(self): order1 = Order( ModelFactory.build_order_state_from_nos( ModelFactory.build_new_order_request(timestamp=0, cl_id='TestClient', cl_ord_id="1", portf_id="TestPortf", broker_id="TestBroker", inst_id="HSI@SEHK", action=Buy, type=Limit, qty=1000, limit_price=18.5))) status_update1 = ModelFactory.build_order_status_update( timestamp=0, broker_id="TestBroker", broker_event_id="1", broker_ord_id="1", cl_id='TestClient', cl_ord_id="1", status=Rejected) order1.on_ord_upd(status_update1) self.assertTrue(order1.is_done()) order2 = Order( ModelFactory.build_order_state_from_nos( ModelFactory.build_new_order_request(timestamp=0, cl_id='TestClient', cl_ord_id="2", portf_id="TestPortf", broker_id="TestBroker", inst_id="HSI@SEHK", action=Buy, type=Limit, qty=1000, limit_price=18.5))) status_update2 = ModelFactory.build_order_status_update( timestamp=0, broker_id="TestBroker", broker_event_id="2", broker_ord_id="2", cl_id='TestClient', cl_ord_id="2", status=Cancelled) order2.on_ord_upd(status_update2) self.assertTrue(order1.is_done()) order3 = Order( ModelFactory.build_order_state_from_nos( ModelFactory.build_new_order_request(timestamp=0, cl_id='TestClient', cl_ord_id="3", portf_id="TestPortf", broker_id="TestBroker", inst_id="HSI@SEHK", action=Buy, type=Limit, qty=1000, limit_price=18.5))) status_update3 = ModelFactory.build_order_status_update( timestamp=0, broker_id="TestBroker", broker_event_id="3", broker_ord_id="3", cl_id='TestClient', cl_ord_id="3", status=Filled) order3.on_ord_upd(status_update3) self.assertTrue(order3.is_done())