Ejemplo n.º 1
0
        public Order AddOrder(Order order)
        {
            // TODO: This error message should be changes as its somewhat a security flaw. It could be abused to find out which companies are in the system
            var company = _companyContext.GetCompany(order.CompanySymbol);

            if (company == null)
            {
                throw new Exception("Cannot create orders for a company that does not exist");
            }

            ProcessExistingOrders(order, company);

            var newOrder = _orderContext.AddOrder(order);

            ProcessNewOrder(newOrder, company);

            return(newOrder);
        }
Ejemplo n.º 2
0
        public Order IssueShares(string symbol, int price, int quantity)
        {
            var company = _companyContext.GetCompany(symbol);

            if (company == null)
            {
                throw new Exception("No company with this symbol exists");
            }

            var issueOrder = new Order(symbol, price, price, quantity, OrderType.Sell)
            {
                AmountRemaining = 0
            };
            var order = _orderContext.AddOrder(issueOrder);

            // Only increment the number of shares if the order was successful
            company.TotalNumberOfShares     += quantity;
            company.RemainingNumberOfShares += quantity;

            return(order);
        }