public decimal ExecuteOrder(string clientId, Order order)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw new ArgumentException("clientId");
            }

            var bestQuotes = GetBestQuotes(order.LotSize).ToArray();

            var price = AllocateOrder(clientId, order, bestQuotes);

            return price;
        }
        public void RejectedOrders()
        {
            //i.e. size over 200 or less than 0 or bad increment
            AssertException.Throws<ArgumentException>(() => { new Order(Direction.Buy, 210); });
            AssertException.Throws<ArgumentException>(() => { new Order(Direction.Buy, -10); });
            AssertException.Throws<ArgumentException>(() => { new Order(Direction.Buy, -1); });
            AssertException.Throws<ArgumentException>(() => { new Order(Direction.Buy, 0); });
            AssertException.Throws<ArgumentException>(() => { new Order(Direction.Buy, 1); });
            AssertException.Throws<ArgumentException>(() => { new Order(Direction.Buy, 9); });
            AssertException.Throws<ArgumentException>(() => { new Order(Direction.Buy, 199); });
            AssertException.Throws<ArgumentException>(() => { new Order(Direction.Buy, 201); });

            var order = new Order(Direction.Buy, 10);
            AssertException.Throws<ArgumentException>(() => { _service.ExecuteOrder(string.Empty, order); });
            AssertException.Throws<ArgumentException>(() => { _service.ExecuteOrder(null, order); });
        }
        private decimal AllocateOrder(string clientId, Order order, Quote[] quotes)
        {
            decimal totalPrice = 0;

            foreach (var quote in quotes)
            {
                _brokers[quote.BrokerId].AddVolume(quote.LotSize);
                totalPrice += quote.PriceAfterCommission;
            }

            AllocatedOrder ao = new AllocatedOrder(order, totalPrice, quotes);

            if (_orders.ContainsKey(clientId) == false)
            {
                _orders.Add(clientId, new List<AllocatedOrder> {ao});
            }
            else
            {
                _orders[clientId].Add(ao);
            }

            return totalPrice;
        }
 public AllocatedOrder(Order clientOrder, decimal orderPrice, IEnumerable<Quote> quotes)
 {
     ClientOrder = clientOrder;
     OrderPrice = orderPrice;
     BrokerQuotes = quotes;
 }