Exemple #1
0
        public void PartialFillForGreaterThanOrEqualToCurrentQuantityThrows(decimal orderQty,
                                                                            decimal fillQty)
        {
            var totalQ = orderQty;
            var clipQ  = orderQty;

            var expected   = DefaultFakeOrderRecord(quantity: totalQ);
            var mockServer = new Mock <IServerFacade>();

            mockServer.Setup(s => s.CreateOrder(It.IsAny <OrderRecord>())).Returns(true);

            const decimal priceDelta = 0;
            var           iceberg    = new IcebergOrder(mockServer.Object,
                                                        expected.Symbol,
                                                        expected.ClOrdID,
                                                        expected.Side,
                                                        expected.Quantity,
                                                        clipQ,
                                                        expected.Price,
                                                        priceDelta);

            iceberg.Activate();

            const string orderID = "FakeOrderID";

            iceberg.ActivatedMarketOrderAccepted(orderID);

            Assert.Throws <ApplicationException>(() => iceberg.OnPartialFill(fillQty));

            mockServer.Verify(s => s.CreateOrder(It.IsAny <OrderRecord>()),
                              Times.Once());
        }
Exemple #2
0
        public void PartialFillAdjustsLastTradedTime()
        {
            const decimal totalQ = 20;
            const decimal clipQ  = 10;

            var expected   = DefaultFakeOrderRecord(quantity: totalQ);
            var mockServer = new Mock <IServerFacade>();

            mockServer.Setup(s => s.CreateOrder(It.IsAny <OrderRecord>())).Returns(true);

            const decimal priceDelta = 0;
            var           iceberg    = new IcebergOrder(mockServer.Object,
                                                        expected.Symbol,
                                                        expected.ClOrdID,
                                                        expected.Side,
                                                        expected.Quantity,
                                                        clipQ,
                                                        expected.Price,
                                                        priceDelta);

            iceberg.Activate();

            const string orderID = "FakeOrderID";

            iceberg.ActivatedMarketOrderAccepted(orderID);

            const decimal fillQ = 5;

            Assert.IsNull(iceberg.LastTradedTime);
            iceberg.OnPartialFill(fillQ);
            Assert.NotNull(iceberg.LastTradedTime);

            mockServer.Verify(s => s.CreateOrder(It.IsAny <OrderRecord>()),
                              Times.Once());
        }
Exemple #3
0
        public void PartialFillAdjustsCurrentAndRemainingQuantity()
        {
            const decimal totalQ = 20;
            const decimal clipQ  = 10;

            var expected   = DefaultFakeOrderRecord(quantity: totalQ);
            var mockServer = new Mock <IServerFacade>();

            mockServer.Setup(s => s.CreateOrder(It.IsAny <OrderRecord>())).Returns(true);

            const decimal priceDelta = 0;
            var           iceberg    = new IcebergOrder(mockServer.Object,
                                                        expected.Symbol,
                                                        expected.ClOrdID,
                                                        expected.Side,
                                                        expected.Quantity,
                                                        clipQ,
                                                        expected.Price,
                                                        priceDelta);

            iceberg.Activate();

            const string orderID = "FakeOrderID";

            iceberg.ActivatedMarketOrderAccepted(orderID);

            const decimal fillQ = 5;

            iceberg.OnPartialFill(fillQ);

            mockServer.Verify(s => s.CreateOrder(It.IsAny <OrderRecord>()),
                              Times.Once());

            Assert.AreEqual(clipQ - fillQ,
                            iceberg.CurrentQuantity,
                            "Current quantity not updated correctly");
            Assert.AreEqual(totalQ - fillQ,
                            iceberg.RemainingQuantity,
                            "Remaining quantity not updated correctly");
        }
Exemple #4
0
        public void PartialFillThenTotalFillOnlyRemovesAClipSizeOfQuantity()
        {
            const decimal totalQ = 25;
            const decimal clipQ  = 10;

            var expected   = DefaultFakeOrderRecord(quantity: totalQ);
            var mockServer = new Mock <IServerFacade>();

            mockServer.Setup(s => s.CreateOrder(It.IsAny <OrderRecord>())).Returns(true);

            const decimal priceDelta = 0;
            var           iceberg    = new IcebergOrder(mockServer.Object,
                                                        expected.Symbol,
                                                        expected.ClOrdID,
                                                        expected.Side,
                                                        expected.Quantity,
                                                        clipQ,
                                                        expected.Price,
                                                        priceDelta);

            iceberg.Activate();

            var idGen = new SimpleOrderIDGenerator();

            iceberg.ActivatedMarketOrderAccepted(idGen.GetID());

            iceberg.OnPartialFill(5);
            iceberg.OnTotalFill();

            mockServer.Verify(s => s.CreateOrder(It.IsAny <OrderRecord>()),
                              Times.Exactly(2));

            Assert.AreEqual(clipQ,
                            iceberg.CurrentQuantity,
                            "Order not refilled to correct clip size");
            Assert.AreEqual(totalQ - clipQ,
                            iceberg.RemainingQuantity,
                            "Remaining quantity should be total minus one clip");
        }
Exemple #5
0
        public void PartialFillWhileOrderInactiveThrows()
        {
            var expected   = DefaultFakeOrderRecord();
            var mockServer = new Mock <IServerFacade>();

            mockServer.Setup(s => s.CreateOrder(It.IsAny <OrderRecord>())).Returns(true);

            var           clipSize   = expected.Quantity;
            const decimal priceDelta = 0;
            var           iceberg    = new IcebergOrder(mockServer.Object,
                                                        expected.Symbol,
                                                        expected.ClOrdID,
                                                        expected.Side,
                                                        expected.Quantity,
                                                        clipSize,
                                                        expected.Price,
                                                        priceDelta);

            Assert.AreEqual(IcebergOrder.ActivationState.Suspended,
                            iceberg.State,
                            "Order should not be active");

            Assert.Throws <ApplicationException>(() => iceberg.OnPartialFill(1));
        }