示例#1
0
        public async Task <RedditDdDtoList> GetDdList(RedditOtherRequest request)
        {
            var entities = await _stocksRepository.GetRedditDdEntities(request);

            var dtos      = _mapper.Map <List <RedditDdDto> >(entities);
            var ddDtoList = await _stockPriceProvider.GetStockPricesForUi(dtos, request);

            return(ddDtoList);
        }
示例#2
0
        public async Task <List <RedditDdEntity> > GetRedditDdEntities(RedditOtherRequest request)
        {
            var result = await _stocksContext.RedditDdEntities
                         .Where(x => x.created_utc >= request.DateFrom.ToUnixTimeSeconds() &&
                                x.created_utc <= request.DateTo.ToUnixTimeSeconds() &&
                                x.score > 0
                                ).ToListAsync();

            return(result);
        }
示例#3
0
        public async Task <RedditDdDtoList> GetDdList(RedditOtherRequest payload)
        {
            var request = new HttpRequestMessage(HttpMethod.Post, $"/api/Reddit/Dd");

            request.Content    = JsonContent.Create(payload);
            using var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

            var result = await response.Content.ReadAsAsync <RedditDdDtoList>();

            return(result);
        }
示例#4
0
        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
                }
            });
        }
示例#5
0
        public async Task <RedditDdDtoList> Dd(RedditOtherRequest request)
        {
            var result = await _redditOtherProvider.GetDdList(request);

            return(result);
        }
示例#6
0
 public Task <RedditDdDtoList> GetStockPricesForUi(List <RedditDdDto> dto, RedditOtherRequest request)
 {
     throw new NotImplementedException();
 }