상속: IBestPriceTrigger
        public void ShouldNotTriggerSellSideOnHigherBidAndAskPrice()
        {
            bool triggered = false;

            var trigger = new BestPriceTrigger("abc", 40, WayEnum.Sell);
            trigger.SetTriggerAction(() => triggered = true);

            var bb = new OrderBookBestBidAsk("abc");
            bb.Set(50, 51, 1, 1);

            var triggerResult = trigger.TryExecute(bb);

            Assert.IsFalse(triggerResult);
            Assert.IsFalse(triggered);
        }
        public void ShouldNotTriggerBuySideOnLowerBidPrice()
        {
            bool triggered = false;

            var trigger = new BestPriceTrigger("abc", 10.4d, WayEnum.Buy);
            trigger.SetTriggerAction(() => triggered = true);

            var bb = new OrderBookBestBidAsk("abc");
            bb.Set(9.4d, null, 1, 1);

            var triggerResult = trigger.TryExecute(bb);

            Assert.IsFalse(triggerResult);
            Assert.IsFalse(triggered);
        }
        public IStopLimitOrder NewStopLimitOrder(string symbol, int clientId, double triggerPrice, double limitPrice, int quantity, WayEnum way)
        {
            if (!ClientStopLimitOrders.ContainsKey(clientId))
                ClientStopLimitOrders.Add(clientId, new EditableList<IStopLimitOrder>());

            var trigger = new BestPriceTrigger(symbol, triggerPrice, way);
            var toReturn = new StopLimitOrder(symbol, quantity, limitPrice, triggerPrice, way, clientId, trigger );

            toReturn.SetExchangeOrderId(globalItemCounter);
            StopLimitOrders.Add(globalItemCounter, toReturn);
            ClientStopLimitOrders[clientId].Add(toReturn);
            toReturn.RegisterOrderRepositoryDeleteHandler(HandleDeletedStopLimitOrder);

            globalItemCounter++;
            return toReturn;
        }
        public void ShouldRemoveTriggerWhenTriggerIsExecuted()
        {
            var orderBookBestBidAsk = new OrderBookBestBidAsk("ABC");
            var book = new OrderBook("ABC", limitOrderMatchingAlgorithmMock, marketOrderMatchingAlgorithmMock, 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);
        }
        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, 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);
        }
        public void ShouldTriggerBuySideOnEqualBidHigherAskPrice()
        {
            bool triggered = false;

            var trigger = new BestPriceTrigger("abc", 50d, WayEnum.Buy);
            trigger.SetTriggerAction(() => triggered = true);

            var bb = new OrderBookBestBidAsk("abc");
            bb.Set(50, 51, 1, 1);

            var triggerResult = trigger.TryExecute(bb);

            Assert.IsTrue(triggerResult);
            Assert.IsTrue(triggered);
        }