コード例 #1
0
        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();
                    }
                }
            }
        }
コード例 #2
0
        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");
                    }
                }
            }
        }