public JsonElement GetFinancials(string ticker) { var webScraper = new StocksWebScraping(); string strResult = webScraper.GetFinancials(ticker.ToUpper()); JsonElement result = GetJsElemFromString(strResult); return(result); }
public JsonElement GetIndicatorsVsIndustry(string ticker) { var webScraper = new StocksWebScraping(); Dictionary <string, double> dictIndicators = webScraper.GetIndicatorsVsIndustry(ticker.ToUpper()); string strResult = string.Empty; JsonElement result = new JsonElement(); if (dictIndicators.Any()) { strResult = JsonSerializer.Serialize <Dictionary <string, double> >(dictIndicators); result = GetJsElemFromString(strResult); } return(result); }
public async Task <Company> GetBasePropOfCompany(string ticker) { // тикер должен быть написан большими буквами, иначе возможны ошибки в запросах к другим сайтам ticker = ticker.ToUpper(); var company = new Company(); string result = await SendWebRequest($"https://www.gurufocus.com/reader/_api/stocks/{ticker}/summary"); JsonElement root = GetJsElemFromString(result); var webScraper = new StocksWebScraping(); try { company.Ticker = ticker.ToUpper(); company.Sector = root.GetProperty("sector").GetString(); company.Name = root.GetProperty("company").GetString(); company.StockId = root.GetProperty("stockid").GetString(); company.Price = root.GetProperty("price").GetDouble(); company.FinancialStrength = root.GetProperty("rank_balancesheet").GetInt32(); company.ProfitabilityRank = root.GetProperty("rank_profitability").GetInt32(); company.ValuationRank = webScraper.GetValuationRank(ticker); // получим описание и лого компании через StocksWebScraping webScraper.GetLogoAndDescription( ticker, out string description, out string logoLink); company.Description = description; // проверим, нет ли лого компании в нашем облаке Cloudinary SearchLogoInCloud(ticker, ref logoLink); company.LogoUrl = logoLink; return(company); } catch { return(new Company()); } }
public async Task UpdateStockCategory(string category) { category = category.ToLower(); var categoryLinks = new List <string>(); var tickers = new List <string>(); var webScraper = new StocksWebScraping(); // в companieslist.json лежат ссылки на finviz с отобранными по фильтрам акциями для основных категорий categoryLinks = await GetCategoryInfoFromFile("companieslist.json", category); if (categoryLinks.Any()) { tickers = webScraper.GetTickersFromFinviz(categoryLinks); } else { // если ссылок на finviz для запрошенной category нет, пробуем искать сами тикеры в OtherCompanies.json tickers = await GetCategoryInfoFromFile("OtherCompanies.json", category); } if (!tickers.Any()) { throw new AppException($"Нет данных для категории {category}"); } var updatedCategory = new List <Company>(); bool checkConditions = ( category == "growrecommendations" || category == "biotech" || category == "dividends"); tickers = tickers.Distinct().ToList(); foreach (string ticker in tickers) { Company company = await GetBasePropOfCompany(ticker); company.Category = category; List <MedpsGurufocusModel> stockPriceList = await GetStockPriceList(company.StockId); if (stockPriceList.Any()) { company.Status = GetStockValuation(company.Price, stockPriceList); if (checkConditions) { bool meetConditions = CheckConditions(company, stockPriceList); if (!meetConditions) { continue; } } } updatedCategory.Add(company); } if (updatedCategory.Any()) { // удаляем все компании этой категории из БД, т.к. постоянно может быть разный набор подходящих компаний // а затем добавляем обновленный список var oldCategory = _context.Companies.Where(x => x.Category == category); _context.Companies.RemoveRange(oldCategory); _context.Companies.AddRange(updatedCategory); await _context.SaveChangesAsync(); } }