Example #1
0
        public OrderDto PlaceOrder(string symbol, decimal minPriceInPoundSterling, decimal maxPriceInPoundSterling,
                                   int quantity, OrderType type)
        {
            var orderDto2 = new OrderDto(symbol, minPriceInPoundSterling, maxPriceInPoundSterling, quantity, type);

            var orderDto = _orderContext.AddOrder(orderDto2);

            return(orderDto.Type == OrderType.Buy ? HandleBuyOrder(orderDto) : HandleSellOrder(orderDto));
        }
        ///<inheritdoc />
        public Order AddOrder(Order orderToAdd)
        {
            if (_companyContext.GetCompany(orderToAdd.CompanySymbol) == null)
            {
                return(null);
            }

            var outstandingOrdersForSymbolInPriceRange = _orderContext.GetOutstandingOrders()
                                                         .Where(x => x.CompanySymbol == orderToAdd.CompanySymbol)                                                // Match orders for company which matches
                                                         .Where(x => x.OrderType != orderToAdd.OrderType)                                                        // Only show buy orders if current is sell and vice versa
                                                         .Where(x => x.MinOrderPrice <= orderToAdd.MaxOrderPrice && x.MaxOrderPrice >= orderToAdd.MinOrderPrice) // Price ranges overlap
                                                         .OrderBy(x => x.Created);                                                                               // Fill oldest orders first

            foreach (var outstandingOrder in outstandingOrdersForSymbolInPriceRange)
            {
                // Find the lower value of quantity remaining
                var numberOfShares = Math.Min(orderToAdd.QuantityRemaining, outstandingOrder.QuantityRemaining);

                // Update the remaining quantity on both orders
                outstandingOrder.QuantityRemaining -= numberOfShares;
                orderToAdd.QuantityRemaining       -= numberOfShares;

                // Update existing order
                _orderContext.UpdateOrder(outstandingOrder);

                // Exit if no more can be filled
                if (orderToAdd.QuantityRemaining == 0)
                {
                    break;
                }
            }

            return(_orderContext.AddOrder(orderToAdd));
        }
        ///<inheritdoc />
        public Order IssueShares(string companySymbol, int quantity, decimal price)
        {
            if (_companyContext.GetCompany(companySymbol) == null)
            {
                return(null);
            }

            var orderToAdd = new Order(companySymbol, price, price, quantity, OrderType.Sell);

            var orderAdded = _orderContext.AddOrder(orderToAdd);

            return(orderAdded);
        }
Example #4
0
 public void AddOrder(Order order)
 {
     Context.AddOrder(order);
 }