public async Task <List <Stock> > GetStockList() { var stockList = await _stockListService.GetStockList(); var stocks = _mapper.Map <List <Stock> >(stockList.symbolsList); //await _stockRepoFacade.SaveStocks(stocks); return(stocks); }
public async Task <RedditDdDtoList> GetStockPricesForUi(List <RedditDdDto> dtos, RedditOtherRequest request) { string pattern = @"[A-Z]{2,}"; var regex = new Regex(pattern); var tickers = new List <string>(); var validatedTickers = new List <string>(); var stockList = await _stockListService.GetStockList(); foreach (var dto in dtos) { if (!string.IsNullOrWhiteSpace(dto.title)) { var potentialTickers = dto.title.Split(); var uppercaseTickers = new List <string>(); foreach (var val in potentialTickers) { var match = regex.Match(val); if (!string.IsNullOrWhiteSpace(match.Value) && !StockLists.TickerBlackList.Contains(match.Value)) { if (!tickers.Contains(match.Value)) { tickers.Add(match.Value); } uppercaseTickers.Add(match.Value); } } dto.PotentialTickers = uppercaseTickers; } } foreach (var ticker in tickers) { if (stockList.Select(x => x.Symbol).Contains(ticker)) { validatedTickers.Add(ticker); } } var result = new List <StockPriceHistoric>(); if (validatedTickers.Count != 0) { var stockSplits = ListExtensions.Split(validatedTickers, 5); foreach (var stockSplit in stockSplits) { var stockSymbols = StringExtensions.GetSymbolsString(stockSplit); var prices = await _stockPriceService.GetHistoricPrices(stockSymbols, DateTime.Now.AddDays(-100), DateTime.Now); if (prices.HistoricalStockList != null) { foreach (var price in prices.HistoricalStockList) { result.Add(price); } } } } foreach (var dto in dtos) { dto.Prices = new StockPricesForUi(); foreach (var potentialTicker in dto.PotentialTickers) { var prices = result.Where(x => x.Symbol.Contains(potentialTicker)).ToList(); if (prices.Count != 0 && prices[0].Historical != null && prices[0].Historical.Count >= 61) { dto.Ticker = prices[0].Symbol; if (prices[0].Historical[0] != null) { if (prices[0]?.Historical[1] != null) { dto.Prices.Day = new StockPriceForUi() { Performance = decimal.Round(((prices[0].Historical[0].AdjClose - prices[0].Historical[1].AdjClose) / prices[0].Historical[1].AdjClose), 2, MidpointRounding.AwayFromZero) //.ToString("P2", new NumberFormatInfo { PercentPositivePattern = 1, PercentNegativePattern = 1 }) }; } if (prices[0]?.Historical[5] != null) { dto.Prices.Week = new StockPriceForUi() { Performance = decimal.Round(((prices[0].Historical[0].AdjClose - prices[0].Historical[5].AdjClose) / prices[0].Historical[5].AdjClose), 2, MidpointRounding.AwayFromZero) //.ToString("P2", new NumberFormatInfo { PercentPositivePattern = 1, PercentNegativePattern = 1 }) }; } if (prices[0]?.Historical[20] != null) { dto.Prices.Month = new StockPriceForUi() { Performance = decimal.Round(((prices[0].Historical[0].AdjClose - prices[0].Historical[20].AdjClose) / prices[0].Historical[20].AdjClose), 2, MidpointRounding.AwayFromZero) //.ToString("P2", new NumberFormatInfo { PercentPositivePattern = 1, PercentNegativePattern = 1 }) }; } if (prices[0]?.Historical[60] != null) { dto.Prices.ThreeMonths = new StockPriceForUi() { Performance = decimal.Round(((prices[0].Historical[0].AdjClose - prices[0].Historical[60].AdjClose) / prices[0].Historical[60].AdjClose), 2, MidpointRounding.AwayFromZero) //.ToString("P2", new NumberFormatInfo { PercentPositivePattern = 1, PercentNegativePattern = 1 }) }; } } } } } return(new RedditDdDtoList() { Aggregated = GetAggregateds(dtos), Items = dtos, Paging = new PagingModel() { Page = request.Page, PageSize = request.RowsPerPage, TotalItems = result.Count } }); }
public async Task <IActionResult> GetStockList() { var result = await _stockListService.GetStockList(); return(Ok(result.Count)); }