private void UpdateStockPrices(object state) { lock(updateStockPricesLock) { if(!updatingStockPrices) { updatingStockPrices = true; using(Controllers.DetailedInfosStocksController controller = new Controllers.DetailedInfosStocksController()) { IEnumerable<Models.DetailedQuoteQueryResultModel> infos = controller.RetrieveStockDetailedInfos(); List<string> codes = infos.Select(p => p.Symbol).ToList(); foreach(StockDescription description in stockDescriptionServices.GetMany(p => codes.Contains(p.Code))) { var info = infos.Where(p => p.Symbol == description.Code).FirstOrDefault<Models.DetailedQuoteQueryResultModel>(); description.FillInfos(info); if(description.HasChanged) { stockDescriptionServices.UpdateStockDescription(description); //To test updates and styles at frontend //description.ChangePercent = random.NextDouble(); //description.LastPrice *= random.NextDouble() + 0.5; BroadcastStockPrice(description); } } } updatingStockPrices = false; } } }
public Stock(int portfolioId, string code, int nbShares, double investedValue, StockDescription description) { Controllers.DetailedInfosStocksController controller = new Controllers.DetailedInfosStocksController(); Models.DetailedQuoteQueryResultModel infos = controller.RetrieveStockDetailedInfos(code); PortfolioId = portfolioId; Code = infos.Symbol; NumberOfShares = nbShares; InvestedValue = investedValue; UnitaryPrice = InvestedValue / NumberOfShares; Description = description; FillInfos(infos); }
public void UpdateStockDescription() { using(Controllers.DetailedInfosStocksController controller = new Controllers.DetailedInfosStocksController()) { Models.DetailedQuoteQueryResultModel infos = controller.RetrieveStockDetailedInfos(this.Code); FillInfos(infos); } }
public void UpdateStock(Operation operation) { switch(operation.Sens) { case OperationOnStock.Buy: double invested = operation.NumberOfShares * operation.Price + operation.Fees; this.NumberOfShares += operation.NumberOfShares; this.InvestedValue += invested; this.UnitaryPrice = this.InvestedValue / this.NumberOfShares; break; case OperationOnStock.Sell: this.NumberOfShares -= operation.NumberOfShares; this.InvestedValue -= operation.NumberOfShares * operation.Price; break; default: throw new Exception(); } using(Controllers.DetailedInfosStocksController controller = new Controllers.DetailedInfosStocksController()) { Models.DetailedQuoteQueryResultModel infos = controller.RetrieveStockDetailedInfos(this.Code); FillInfos(infos); } }
private void UpdateStockDescription() { using(Controllers.DetailedInfosStocksController controller = new Controllers.DetailedInfosStocksController()) { IEnumerable<Models.DetailedQuoteQueryResultModel> infos = controller.RetrieveStockDetailedInfos(); List<string> codes = infos.Select(p=>p.Symbol).ToList(); foreach(StockDescription description in stockDescriptionServices.GetMany(p=>codes.Contains(p.Code))) { var info = infos.Where(p => p.Symbol == description.Code).FirstOrDefault < Models.DetailedQuoteQueryResultModel>(); description.FillInfos(info); stockDescriptionServices.UpdateStockDescription(description); } } }