public static void FilterCompanyHasSingleQuoteResult() { using (DbStockMonitor context = new DbStockMonitor()) { List <Company> allCompanyList = context.Companies.AsNoTracking().ToList(); foreach (var company in allCompanyList) { string response = RetrieveJsonDataHelper.GetQuoteStringBySymbol(company.Symbol).Result; if (response.Length < 20) { List <QuoteDaily> dailyQuoteList = context.QuoteDailies.AsNoTracking().Where(q => q.Symbol == company.Symbol).ToList(); Console.Out.WriteLine($"*** Found: {company.Symbol},will remove {dailyQuoteList.Count} records. response: {response}"); for (int i = 0; i < dailyQuoteList.Count; i++) { context.QuoteDailies.Remove(dailyQuoteList[i]); if (i % 50 == 0 && i != 0) { Console.Out.WriteLine($"{company.Symbol}: Deleted 50 records, left: {dailyQuoteList.Count - i}"); } context.SaveChanges(); } context.Companies.Remove(company); context.SaveChanges(); } } } }
public static List <QuoteDaily> GetQuoteDailyList(string symbol) { try { List <QuoteDaily> result = new List <QuoteDaily>(); List <FmgQuoteDaily> quoteList = RetrieveJsonDataHelper.RetrieveFmgDataDaily(symbol); foreach (var dailyQuote in quoteList) { QuoteDaily quoteDaily = new QuoteDaily { Symbol = symbol, Date = dailyQuote.Date, Open = dailyQuote.Open, High = dailyQuote.High, Low = dailyQuote.Low, Close = dailyQuote.Close, Volume = dailyQuote.Volume, Vwap = dailyQuote.Vwap, ChangeOverTime = dailyQuote.ChangeOverTime }; result.Add(quoteDaily); } return(result); } catch (SystemException ex) { throw new SystemException(ex.Message); } }
public static Company GetCompanyBySymbol(string symbol) { try { FmgCompanyProfile fmgCompanyProfile = RetrieveJsonDataHelper.RetrieveFmgCompanyProfile(symbol); FmgInvestmentValuationRatios fmgInvestmentValuationRatios = RetrieveJsonDataHelper.RetrieveFmgInvestmentValuationRatios(symbol); Company company = new Company() { CompanyName = fmgCompanyProfile.CompanyName, Symbol = symbol, Exchange = fmgCompanyProfile.Exchange, MarketCapital = fmgCompanyProfile.MktCap, PriceToEarningRatio = fmgInvestmentValuationRatios.PriceEarningsRatio, PriceToSalesRatio = fmgInvestmentValuationRatios.PriceToSalesRatio, Industry = fmgCompanyProfile.Industry, Sector = fmgCompanyProfile.Sector, Description = fmgCompanyProfile.Description, //Website = fmgCompanyProfile.Website, CEO = fmgCompanyProfile.Ceo, Website = fmgCompanyProfile.Website, Logo = GetImageFromUrl(fmgCompanyProfile.Image) }; return(company); } catch (SystemException ex) { throw new SystemException(ex.Message); } }
public static async Task <UICompanyRowDetail> GetUICompanyRowDetailTask(string symbol, List <UIComapnyRow> companyList) { try { FmgSingleQuote singleQuote = await RetrieveJsonDataHelper.RetrieveFmgSingleQuote(symbol); UIComapnyRow companyRow = companyList.Find(c => c.Symbol == symbol); Company company = DatabaseHelper.GetCompanyFromDb(symbol); UICompanyRowDetail result = new UICompanyRowDetail { Symbol = symbol, Name = company.CompanyName, Price = companyRow.Price, Open = companyRow.Open, High = singleQuote.dayHigh, Low = singleQuote.dayLow, Volume = companyRow.Volume, Change = companyRow.PriceChange, ChangePercentage = companyRow.ChangePercentage, Description = company.Description, Ceo = company.CEO, Industry = company.Industry, Sector = company.Sector }; return(result); } catch (SystemException ex) { throw new SystemException(ex.Message); } }
public static void FirstImportStockListToDatabase() { int counter = 0; using (DbStockMonitor context = new DbStockMonitor()) { counter = context.Companies.Count(); Console.Out.WriteLine($"Counter start: {counter}"); } List <FmgStockListEntity> stockList = RetrieveJsonDataHelper.RetrieveStockList(); Console.Out.WriteLine("***Length of list: " + stockList.Count + "\n\n"); for (int i = 0; i < 5000; i++) { Console.Out.Write($"{i}: "); string symbol = stockList[i].Symbol; Company company = null; try { company = GUIDataHelper.GetCompanyBySymbol(symbol); } catch (Newtonsoft.Json.JsonSerializationException ex) { Console.Out.WriteLine("!!!!! Failed: " + ex.Message + $" <{symbol}> "); } catch (ArgumentException ex) { Console.Out.WriteLine("!!!!! Failed: " + ex.Message + $" <{symbol}> "); } catch (SystemException ex) { Console.Out.WriteLine("!!!!! Failed: " + ex.Message + $" <{symbol}> "); } if (company == null) { continue; } using (DbStockMonitor dbStockContext = new DbStockMonitor()) { dbStockContext.Companies.Add(company); try { dbStockContext.SaveChanges(); Console.Out.WriteLine($">>>>> {++counter}: Successfully insert record: <{company.Symbol}>"); } catch (SystemException ex) { Console.Out.WriteLine($"!!!!! Database save changes exception! <{company.Symbol}>, " + ex.Message); } } } }
public static void FilterSybomlNoQuoteData() { int counter = 0; string filepath = "C:\\Users\\WW\\Desktop\\SourceTree\\IPD20-DotNetProject\\StockMonitor\\InvalidSymbols.txt"; using (DbStockMonitor context = new DbStockMonitor()) { List <string> symbolList = context.Companies.AsNoTracking().Select(p => p.Symbol).ToList(); for (int i = 0; i < symbolList.Count; i++) { string symbol = symbolList[i]; string response = RetrieveJsonDataHelper.GetQuoteStringBySymbol(symbol).Result; if (response.Length < 10) { Console.Out.WriteLine($"<{i}>: find {++counter} - {symbol} single quote has NO data: <{response}>"); File.AppendAllText(filepath, $"{symbol}\n"); } } } }
public static async Task <UIComapnyRow> GetUICompanyRowTaskBySymbol(string symbol) //ex FormatException { //ex: ArgumentException, SystemException, FormatException try { DateTime start = DateTime.Now; FmgQuoteOnlyPrice fmgQuoteOnlyPrice = await RetrieveJsonDataHelper.RetrieveFmgQuoteOnlyPrice(symbol); //ex: ArgumentException FmgSingleQuote singleQuote = await RetrieveJsonDataHelper.RetrieveFmgSingleQuote(symbol); //ex: ArgumentException DateTime end = DateTime.Now; TimeSpan timeSpan = new TimeSpan(); timeSpan = end - start; Console.Out.WriteLine($"Time: {timeSpan.TotalMilliseconds} mills for {symbol}"); Company company = DatabaseHelper.GetCompanyFromDb(symbol); //ex: SystemException return(new UIComapnyRow(company, fmgQuoteOnlyPrice, singleQuote)); //ex: FormatException } catch (SystemException ex) { throw new SystemException(ex.Message); } }
private static async Task <UIComapnyRow> GetWatchUIComanyRowTask(int userId, Company company) { try { Stopwatch sw = Stopwatch.StartNew(); FmgQuoteOnlyPrice fmgQuoteOnlyPrice = await RetrieveJsonDataHelper.RetrieveFmgQuoteOnlyPrice(company.Symbol); FmgSingleQuote singleQuote = await RetrieveJsonDataHelper.RetrieveFmgSingleQuote(company.Symbol); UIComapnyRow companyRow = new UIComapnyRow(company, fmgQuoteOnlyPrice, singleQuote); //ex: FormatException sw.Stop(); Console.Out.WriteLine( $"\n---- Add one companyRow to result in GetWatchUICompanyRowList: {company.Symbol}, time: {sw.Elapsed.TotalMilliseconds} mills"); return(companyRow); } catch (SystemException ex) { throw new SystemException(ex.Message); } }