public async System.Threading.Tasks.Task PostAsync([FromUri] string value) { // Decoding input var firstDelimiter = value.IndexOf(';'); var lastDelimiter = value.LastIndexOf(';'); var username = value.Substring(0, firstDelimiter); var stockname = value.Substring(firstDelimiter + 1, value.Length - (firstDelimiter + 1)); stockname = stockname.Substring(0, stockname.IndexOf(';')); var amount = value.Substring(lastDelimiter + 1, value.Length - (lastDelimiter + 1)); int amountInt; if (int.TryParse(amount, out amountInt)) { var stock = new Common.Stock() { StockName = stockname, StockType = Common.Stock.SaleOrPurchase.Purchase, Username = username, Amount = amountInt }; await Buyer.PlaceRequestAsync(stock); } }
public void AddStock(string symbol, decimal? price = null) { var stock = new Stock { Symbol = symbol, Price = price.GetValueOrDefault(_priceRandomizer.Next(10, 700)) }; AddStock(stock); }
public void Handle(IStockChangeEvent message) { var symbol = message.Symbol; var stock = _stocks.GetStockBySymbol(symbol); if (stock == null) { stock = new Stock { Symbol = symbol, Price = message.Price }; _stocks.AddStock(stock); GetClients().addStock(message); } else { stock.Price = message.Price; GetClients().updateStockPrice(message); } }
public static IStockChangeEvent Create(Stock stock) { StockPriceChange change; if (stock.Change > 0) change = new StockPriceIncrease(); else if (stock.Change < 0) change = new StockPriceDecrease(); else { return null; } change.Change = stock.Change; change.DayHigh = stock.DayHigh; change.DayLow = stock.DayLow; change.DayOpen = stock.DayOpen; change.LastChange = stock.LastChange; change.PercentChange = stock.PercentChange; change.Price = stock.Price; change.Symbol = stock.Symbol; return change; }
public void AddStock(Stock stock) { _stocks.Add(stock.Symbol, stock); }
public void AddStock(Stock stock) { _stocks.AddStock(stock); if (stock == null) return; stock.Price += GetRandomPriceChange(stock); if (StockChanged != null) StockChanged(this, new EventArgs<Stock>(stock)); }
private decimal GetRandomPriceChange(Stock stock) { // Update the stock price by a random factor of the range percent var random = new Random((int)Math.Floor(stock.Price)); var percentChange = random.NextDouble() * RangePercent; var pos = random.NextDouble() > .51; var change = Math.Round(stock.Price * (decimal)percentChange, 2); change = pos ? change : -change; return change; }