public bool Buy(Trader trader, StockRequest request) { if (!sellers.ContainsKey(request.Symbol)) { AddBuyer(trader); Console.WriteLine("There are no sellers for {0}", request.Symbol); return(false); } List <Trader> sellersOfStock = sellers[request.Symbol]; var couldBuyStocks = sellersOfStock.Any(s => s.AcceptSell(request)); if (!couldBuyStocks) { AddBuyer(trader); Console.WriteLine("No one seller sells it at this price, try a higher price"); } else { Console.WriteLine("Actions bought"); } return(couldBuyStocks); }
public virtual bool AcceptSell(StockRequest request) { if (request.Price >= Price) { Console.WriteLine("{0} will sell {1} actions of {2} at the price of {3} to {4}", Name, request.Count, request.Symbol, request.Price, request.Requester); return(true); } return(false); }
public bool Sell(Trader trader, StockRequest request) { if (!buyers.ContainsKey(request.Symbol)) { AddSeller(trader); Console.WriteLine("There are no buyers for {0}", request.Symbol); return(false); } var couldSellStocks = buyers[request.Symbol].Any(b => b.AcceptBuy(request)); if (!couldSellStocks) { AddSeller(trader); Console.WriteLine("No buyer buys it at this price, try a lower price"); } return(couldSellStocks); }