public List <PriceModel> GetLastPrices() { var lastPrices = _priceRepository.FindPrices() .GroupBy(x => x.SymbolId) .Select(x => x.OrderByDescending(y => y.Date).Last()) .Select(x => new PriceModel() { SymbolId = x.SymbolId, Price = x.Price, Date = x.Date }) .ToList(); var symbols = _symbolManager.GetSymbols(); foreach (var symbol in symbols) { var lastPrice = lastPrices.FirstOrDefault(x => x.SymbolId == symbol.Id); if (lastPrice == null) { string symbolId = symbol.Id; decimal price = GetLatestPrice(symbol); DateTime date = DateTime.Now; lastPrices.Add(new PriceModel() { SymbolId = symbolId, Price = price, Date = date }); SaveLastPrice(symbolId, price, 0, DateTime.Now, date); } } return(lastPrices); }
public void UpdateSymbols() { Symbols = _symbolManager.GetSymbols(); }