Пример #1
0
        public void ShouldIgnoreOrderWithDifferentPriceOnAdd()
        {
            IPriceSlot priceSlot = new PriceSlot(90, new LimitOrderMatchingAlgorithm(new DateService()), new MarketOrderMatchingAlgorithm(new DateService()));
            var        buyOrder  = new LimitOrder("ABC", 10, 91, WayEnum.Buy, 9);

            priceSlot.AddOrder(buyOrder);

            Assert.AreEqual(0, priceSlot.BuyOrders.Count);
        }
Пример #2
0
        public void ShouldAddSellOrder()
        {
            IPriceSlot priceSlot = new PriceSlot(90, new LimitOrderMatchingAlgorithm(new DateService()), new MarketOrderMatchingAlgorithm(new DateService()));
            var        sellOrder = new LimitOrder("ABC", 10, 90, WayEnum.Sell, 9);

            priceSlot.AddOrder(sellOrder);

            Assert.AreEqual(1, priceSlot.SellOrders.Count);
            Assert.AreEqual(sellOrder, priceSlot.SellOrders[0]);
        }
Пример #3
0
        public void ShouldReturnTrueWhenBuyAndSellOrdersArePresent()
        {
            var slot = new PriceSlot(90, new LimitOrderMatchingAlgorithm(new DateService()), new MarketOrderMatchingAlgorithm(new DateService()));

            var buyOrder  = new LimitOrder("ABC", 50, 90, WayEnum.Buy, 80);
            var sellOrder = new LimitOrder("ABC", 50, 90, WayEnum.Sell, 80);

            slot.AddOrder(buyOrder);
            slot.AddOrder(sellOrder);

            Assert.IsTrue(slot.HasOrders);
        }
Пример #4
0
        public void ShouldRemoveBuyOrder()
        {
            IPriceSlot priceSlot = new PriceSlot(90, new LimitOrderMatchingAlgorithm(new DateService()), new MarketOrderMatchingAlgorithm(new DateService()));
            var        buyOrder  = new LimitOrder("ABC", 10, 90, WayEnum.Buy, 9);

            priceSlot.AddOrder(buyOrder);

            Assert.AreEqual(1, priceSlot.BuyOrders.Count);
            Assert.AreEqual(buyOrder, priceSlot.BuyOrders[0]);

            priceSlot.RemoveOrder(buyOrder);
            Assert.AreEqual(0, priceSlot.BuyOrders.Count);
        }
Пример #5
0
        public void ShouldMatchMultipleSellOrdersToSameBuyOrder()
        {
            var executions    = new List <INewExecution>();
            var executionalgo = new LimitOrderMatchingAlgorithm(new DateService());

            executionalgo.AddExecutionsHandler(executions.Add);

            var priceSlot = new PriceSlot(90, executionalgo, new MarketOrderMatchingAlgorithm(new DateService()));

            var sellOrder1 = new LimitOrder("ABC", 10, 90, WayEnum.Sell, 90);
            var sellOrder2 = new LimitOrder("ABC", 40, 90, WayEnum.Sell, 90);
            var buyOrder   = new LimitOrder("ABC", 50, 90, WayEnum.Buy, 80);

            priceSlot.AddOrder(sellOrder1);
            priceSlot.AddOrder(sellOrder2);
            priceSlot.TryMatchLimitOrder(buyOrder);

            Assert.AreEqual(2, executions.Count);
            Assert.AreEqual(0, priceSlot.BuyOrders.Count);
            Assert.AreEqual(0, priceSlot.SellOrders.Count);
        }
Пример #6
0
        public void ShouldMatchBuyOrderCompletely()
        {
            var executions    = new List <INewExecution>();
            var executionalgo = new LimitOrderMatchingAlgorithm(new DateService());

            executionalgo.AddExecutionsHandler(executions.Add);



            var priceSlot = new PriceSlot(90, executionalgo, new MarketOrderMatchingAlgorithm(new DateService()));

            var sellOrder = new LimitOrder("ABC", 100, 90, WayEnum.Sell, 90);
            var buyOrder  = new LimitOrder("ABC", 10, 90, WayEnum.Buy, 80);

            priceSlot.AddOrder(sellOrder);
            priceSlot.TryMatchLimitOrder(buyOrder);

            Assert.AreEqual(1, executions.Count);
            Assert.AreEqual(0, priceSlot.BuyOrders.Count);
            Assert.AreEqual(1, priceSlot.SellOrders.Count);
            Assert.AreEqual(90, priceSlot.SellOrders[0].Quantity);
        }
Пример #7
0
        public void ShouldReturnFalseWhenNoOrdersArePresent()
        {
            var slot = new PriceSlot(90, new LimitOrderMatchingAlgorithm(new DateService()), new MarketOrderMatchingAlgorithm(new DateService()));

            Assert.IsFalse(slot.HasOrders);
        }