Ejemplo n.º 1
0
        public void ShouldNotMatchSellStopLimitOrderLowerThanMarket()
        {
            var executions = new List <INewExecution>();

            var orderBookBestBidAsk = new OrderBookBestBidAsk("ABC");
            var matchAlgo           = new LimitOrderMatchingAlgorithm(new DateService());

            matchAlgo.AddExecutionsHandler(executions.Add);

            var book = new OrderBook("ABC", matchAlgo, marketOrderMatchingAlgorithmMock.Object, orderBookBestBidAsk);

            var sellOrder1 = new LimitOrder("ABC", 10, 1161.8d, WayEnum.Sell, 9);

            book.AddLimitOrder(sellOrder1);

            var buyOrder1 = new LimitOrder("ABC", 10, 1161.7d, WayEnum.Buy, 9);

            book.AddLimitOrder(buyOrder1);

            var trigger = new BestPriceTrigger("ABC", 1160, WayEnum.Sell);

            trigger.SetTriggerAction(() =>
            {
                Console.WriteLine("Boom!");
                int i = 0;
            });

            var sellStopLimit = new StopLimitOrder("ABC", 1, 1160, 1160, WayEnum.Sell, 5, trigger);

            book.AddStopLimitOrder(sellStopLimit);

            Assert.AreEqual(0, executions.Count);
        }
Ejemplo n.º 2
0
        public void ShouldRemoveTriggerWhenTriggerIsExecuted()
        {
            var orderBookBestBidAsk = new OrderBookBestBidAsk("ABC");
            var book = new OrderBook("ABC", limitOrderMatchingAlgorithmMock.Object, marketOrderMatchingAlgorithmMock.Object, orderBookBestBidAsk);


            var trigger   = new BestPriceTrigger("ABC", 10, WayEnum.Buy);
            var stopOrder = new StopLimitOrder("abc", 10, 90, 90, WayEnum.Buy, 2, trigger);


            trigger.SetTriggerAction(() =>
            {
                stopOrder.Delete();
            });

            book.AddStopLimitOrder(stopOrder);

            Assert.AreEqual(trigger, book.BuySideStopLimitOrders[0].Trigger);

            orderBookBestBidAsk.Set(11, 12, 100, 100);
            trigger.TryExecute(orderBookBestBidAsk);

            Assert.AreEqual(0, book.BuySideStopLimitOrders.Count);
        }