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 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); }
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); }
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); }
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 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); }