Esempio n. 1
0
    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())
Esempio n. 2
0
    def test_leave_qty(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.assertEqual(1000, order.leave_qty())

        er1 = ExecutionReport(cl_id='test',
                              cl_ord_id=1,
                              ord_id=1,
                              er_id=1,
                              inst_id=1,
                              last_qty=800,
                              last_price=18.4,
                              status=OrdStatus.PARTIALLY_FILLED)
        order.on_exec_report(er1)
        self.assertEqual(200, order.leave_qty())

        er2 = ExecutionReport(cl_id='test',
                              cl_ord_id=1,
                              ord_id=1,
                              er_id=2,
                              inst_id=1,
                              last_qty=200,
                              last_price=18.4,
                              status=OrdStatus.FILLED)
        order.on_exec_report(er2)
        self.assertEqual(0, order.leave_qty())
        self.assertTrue(order.is_done())
        self.assertEquals(OrdStatus.FILLED, order.status)
Esempio n. 3
0
    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())
Esempio n. 4
0
    def test_leave_qty(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.assertEqual(1000, order.leave_qty())

        er1 = ExecutionReport(cl_id='test', cl_ord_id=1, ord_id=1, er_id=1, inst_id=1, last_qty=800, last_price=18.4,
                              status=OrdStatus.PARTIALLY_FILLED)
        order.on_exec_report(er1)
        self.assertEqual(200, order.leave_qty())

        er2 = ExecutionReport(cl_id='test', cl_ord_id=1, ord_id=1, er_id=2, inst_id=1, last_qty=200, last_price=18.4,
                              status=OrdStatus.FILLED)
        order.on_exec_report(er2)
        self.assertEqual(0, order.leave_qty())
        self.assertTrue(order.is_done())
        self.assertEquals(OrdStatus.FILLED, order.status)
Esempio n. 5
0
    def test_leave_qty(self):
        order = 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)))
        self.assertEqual(1000, order.leave_qty())

        er1 = ModelFactory.build_execution_report(timestamp=0,
                                                  broker_id="TestBroker",
                                                  broker_event_id="1",
                                                  broker_ord_id="1",
                                                  cl_id='TestClient',
                                                  cl_ord_id="1",
                                                  inst_id="HSI@SEHK",
                                                  last_qty=800,
                                                  last_price=18.4,
                                                  status=PartiallyFilled)
        order.on_exec_report(er1)
        self.assertEqual(200, order.leave_qty())

        er2 = ModelFactory.build_execution_report(timestamp=0,
                                                  broker_id="TestBroker",
                                                  broker_event_id="2",
                                                  broker_ord_id="1",
                                                  cl_id='TestClient',
                                                  cl_ord_id="1",
                                                  inst_id="HSI@SEHK",
                                                  last_qty=200,
                                                  last_price=18.4,
                                                  status=Filled)
        order.on_exec_report(er2)
        self.assertEqual(0, order.leave_qty())
        self.assertTrue(order.is_done())
        self.assertEquals(Filled, order.status())
Esempio n. 6
0
    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())