示例#1
0
        public void ShouldNotMatchOrdersWithZeroQuantity()
        {
            var generatedExecutions = new List <INewExecution>();
            var algo = new LimitOrderMatchingAlgorithm(dateServiceMock);

            algo.AddExecutionsHandler(generatedExecutions.Add);

            ILimitOrder sellOrder = new LimitOrder("ABC", 0, 90, WayEnum.Sell, 13);
            ILimitOrder buyOrder  = new LimitOrder("ABC", 10, 90, WayEnum.Buy, 12);

            algo.TryMatch(buyOrder, sellOrder);
            Assert.AreEqual(0, generatedExecutions.Count);

            sellOrder.Modify(90);
            buyOrder.Modify(0);

            algo.TryMatch(buyOrder, sellOrder);
            Assert.AreEqual(0, generatedExecutions.Count);
        }
示例#2
0
        public void ShouldNotMatchOrdersWithDifferentSymbols()
        {
            var generatedExecutions = new List <INewExecution>();
            var algo = new LimitOrderMatchingAlgorithm(dateServiceMock.Object);

            algo.AddExecutionsHandler(generatedExecutions.Add);

            ILimitOrder sellOrder = new LimitOrder("ABC", 10, 90, WayEnum.Sell, 13);
            ILimitOrder buyOrder  = new LimitOrder("QQQ", 10, 90, WayEnum.Buy, 12);

            algo.TryMatch(buyOrder, sellOrder);
            Assert.AreEqual(0, generatedExecutions.Count);
        }
示例#3
0
        public void ShouldNotMatchHigherSellOrderWithLowerBuyOrder()
        {
            var generatedExecutions = new List <INewExecution>();
            var algo = new LimitOrderMatchingAlgorithm(dateServiceMock);

            algo.AddExecutionsHandler(generatedExecutions.Add);

            ILimitOrder sellOrder = new LimitOrder("ABC", 10, 100, WayEnum.Sell, 13);
            ILimitOrder buyOrder  = new LimitOrder("ABC", 10, 90, WayEnum.Buy, 12);

            algo.TryMatch(buyOrder, sellOrder);
            Assert.AreEqual(0, generatedExecutions.Count);
        }
        public void ShouldExecuteOnLowestQuantity()
        {
            var staticDatetimeOffset = DateTimeOffset.UtcNow;
            dateServiceMock.Stub(a => a.UtcNow()).Return(staticDatetimeOffset);

            var generatedExecutions = new List<INewExecution>();
            var algo = new LimitOrderMatchingAlgorithm(dateServiceMock);
            algo.AddExecutionsHandler(generatedExecutions.Add);

            ILimitOrder sellOrder = new LimitOrder("ABC", 40, 90, WayEnum.Sell, 13);
            ILimitOrder buyOrder = new LimitOrder("ABC", 100, 90, WayEnum.Buy, 12);

            algo.TryMatch(buyOrder, sellOrder);
            Assert.AreEqual(1, generatedExecutions.Count);
            Assert.AreEqual(40, generatedExecutions[0].MatchedQuantity);
        }
        public void OrdersShouldNotHaveModifiedQuantitiesAfterNoMatch()
        {
            var staticDatetimeOffset = DateTimeOffset.UtcNow;
            dateServiceMock.Stub(a => a.UtcNow()).Return(staticDatetimeOffset);

            var generatedExecutions = new List<INewExecution>();
            var algo = new LimitOrderMatchingAlgorithm(dateServiceMock);
            algo.AddExecutionsHandler(generatedExecutions.Add);

            ILimitOrder sellOrder = new LimitOrder("ABC", 40, 91, WayEnum.Sell, 13);
            ILimitOrder buyOrder = new LimitOrder("ABC", 100, 90, WayEnum.Buy, 12);

            algo.TryMatch(buyOrder, sellOrder);
            Assert.AreEqual(40, sellOrder.Quantity);
            Assert.AreEqual(100, buyOrder.Quantity);
        }
示例#6
0
        public void OrdersShouldNotHaveModifiedQuantitiesAfterNoMatch()
        {
            var staticDatetimeOffset = DateTimeOffset.UtcNow;

            dateServiceMock.Stub(a => a.UtcNow()).Return(staticDatetimeOffset);

            var generatedExecutions = new List <INewExecution>();
            var algo = new LimitOrderMatchingAlgorithm(dateServiceMock);

            algo.AddExecutionsHandler(generatedExecutions.Add);

            ILimitOrder sellOrder = new LimitOrder("ABC", 40, 91, WayEnum.Sell, 13);
            ILimitOrder buyOrder  = new LimitOrder("ABC", 100, 90, WayEnum.Buy, 12);

            algo.TryMatch(buyOrder, sellOrder);
            Assert.AreEqual(40, sellOrder.Quantity);
            Assert.AreEqual(100, buyOrder.Quantity);
        }
示例#7
0
        public void ShouldExecuteOnLowestQuantity()
        {
            var staticDatetimeOffset = DateTimeOffset.UtcNow;

            dateServiceMock.Stub(a => a.UtcNow()).Return(staticDatetimeOffset);

            var generatedExecutions = new List <INewExecution>();
            var algo = new LimitOrderMatchingAlgorithm(dateServiceMock);

            algo.AddExecutionsHandler(generatedExecutions.Add);

            ILimitOrder sellOrder = new LimitOrder("ABC", 40, 90, WayEnum.Sell, 13);
            ILimitOrder buyOrder  = new LimitOrder("ABC", 100, 90, WayEnum.Buy, 12);

            algo.TryMatch(buyOrder, sellOrder);
            Assert.AreEqual(1, generatedExecutions.Count);
            Assert.AreEqual(40, generatedExecutions[0].MatchedQuantity);
        }
示例#8
0
        public void ShouldGenerateExecutionWithSamePriceAsBuyAndSell()
        {
            var staticDatetimeOffset = DateTimeOffset.UtcNow;

            dateServiceMock.Stub(a => a.UtcNow()).Return(staticDatetimeOffset);

            var generatedExecutions = new List <INewExecution>();
            var algo = new LimitOrderMatchingAlgorithm(dateServiceMock);

            algo.AddExecutionsHandler(generatedExecutions.Add);

            ILimitOrder sellOrder = new LimitOrder("ABC", 10, 90, WayEnum.Sell, 13);
            ILimitOrder buyOrder  = new LimitOrder("ABC", 10, 90, WayEnum.Buy, 12);

            algo.TryMatch(buyOrder, sellOrder);
            Assert.AreEqual(1, generatedExecutions.Count);

            Assert.AreEqual(10, generatedExecutions[0].MatchedQuantity);
            Assert.AreEqual(90, generatedExecutions[0].MatchedPrice);
            Assert.AreEqual(buyOrder, generatedExecutions[0].BuySideOrder);
            Assert.AreEqual(sellOrder, generatedExecutions[0].SellSideOrder);
            Assert.AreEqual(staticDatetimeOffset, generatedExecutions[0].ExecutionTime);
        }
        public void ShouldNotMatchOrdersWithZeroQuantity()
        {
            var generatedExecutions = new List<INewExecution>();
            var algo = new LimitOrderMatchingAlgorithm(dateServiceMock);
            algo.AddExecutionsHandler(generatedExecutions.Add);

            ILimitOrder sellOrder = new LimitOrder("ABC", 0, 90, WayEnum.Sell, 13);
            ILimitOrder buyOrder = new LimitOrder("ABC", 10, 90, WayEnum.Buy, 12);

            algo.TryMatch(buyOrder, sellOrder);
            Assert.AreEqual(0, generatedExecutions.Count);

            sellOrder.Modify(90);
            buyOrder.Modify(0);

            algo.TryMatch(buyOrder, sellOrder);
            Assert.AreEqual(0, generatedExecutions.Count);
        }
        public void ShouldNotMatchHigherSellOrderWithLowerBuyOrder()
        {
            var generatedExecutions = new List<INewExecution>();
            var algo = new LimitOrderMatchingAlgorithm(dateServiceMock);
            algo.AddExecutionsHandler(generatedExecutions.Add);

            ILimitOrder sellOrder = new LimitOrder("ABC", 10, 100, WayEnum.Sell, 13);
            ILimitOrder buyOrder = new LimitOrder("ABC", 10, 90, WayEnum.Buy, 12);

            algo.TryMatch(buyOrder, sellOrder);
            Assert.AreEqual(0, generatedExecutions.Count);
        }
        public void ShouldGenerateExecutionWithSamePriceAsBuyAndSell()
        {
            var staticDatetimeOffset = DateTimeOffset.UtcNow;
            dateServiceMock.Stub(a => a.UtcNow()).Return(staticDatetimeOffset);

            var generatedExecutions = new List<INewExecution>();
            var algo = new LimitOrderMatchingAlgorithm(dateServiceMock);
            algo.AddExecutionsHandler(generatedExecutions.Add);

            ILimitOrder sellOrder = new LimitOrder("ABC", 10, 90, WayEnum.Sell, 13);
            ILimitOrder buyOrder = new LimitOrder("ABC", 10, 90, WayEnum.Buy, 12);

            algo.TryMatch(buyOrder, sellOrder);
            Assert.AreEqual(1, generatedExecutions.Count);

            Assert.AreEqual(10, generatedExecutions[0].MatchedQuantity);
            Assert.AreEqual(90, generatedExecutions[0].MatchedPrice);
            Assert.AreEqual(buyOrder, generatedExecutions[0].BuySideOrder);
            Assert.AreEqual(sellOrder, generatedExecutions[0].SellSideOrder);
            Assert.AreEqual(staticDatetimeOffset, generatedExecutions[0].ExecutionTime);
        }