//Yahoo Finance Company Cache Entry Update Routine public void UpdateYFCompanyCacheEntry(object key, object value, EvictionReason reason, object state = null) { try { Stopwatch sw = new Stopwatch(); sw.Start(); string cacheKey = (string)key; string channel = cacheKey.Split('-')[0]; string symbol = cacheKey.Split('-')[2]; //Remove before updating and re-adding RemoveCachedSymbol(cacheKey); CompanyStatsYF companyStats = YahooFinance.GetCompanyStatsAsync(symbol).Result; //Save YF Company to cache this.Add(companyStats, cacheKey); string perf = sw.ElapsedMilliseconds.ToString(); } catch (Exception e) { Debug.WriteLine("ERROR UpdateYFCompanyCacheEntry: " + e.Message); } }
public static async Task <CompaniesListYF> GetAllCompaniesAsync() { CompaniesListYF companies = new CompaniesListYF() { SymbolsToCompanies = new Dictionary <string, CompanyYF>() }; string nasdaqData = Companies.GetFromFtpUri(Companies.NasdaqSymbolsUri); string[] nasdaqDataLines = nasdaqData.Split(new[] { Environment.NewLine }, StringSplitOptions.None); for (int i = 1; i < nasdaqDataLines.Length - 1; i++) //trim first and last row { string line = nasdaqDataLines[i]; string[] data = line.Split('|'); if (data.Count() > 3) { string symbol = data[1]; if (!companies.SymbolsToCompanies.ContainsKey(symbol) && !String.IsNullOrEmpty(symbol)) { bool isNasdaq = data[0] == "Y"; if (isNasdaq) { CompanyStatsYF stats = YahooFinance.GetCompanyStatsAsync(symbol).Result; CompanyYF company = new CompanyYF { Symbol = symbol, Exchange = "NASDAQ", Stats = stats }; companies.SymbolsToCompanies.Add(symbol, company); } } } } string otcData = Companies.GetFromFtpUri(Companies.OtcSymbolsUri); string[] otcDataLines = otcData.Split(new[] { Environment.NewLine }, StringSplitOptions.None); for (int j = 1; j < otcDataLines.Length - 1; j++) //trim first and last row { string line = otcDataLines[j]; string[] data = line.Split('|'); if (data.Count() > 3) { string symbol = data[0]; if (!companies.SymbolsToCompanies.ContainsKey(symbol) && !String.IsNullOrEmpty(symbol)) { CompanyStatsYF stats = YahooFinance.GetCompanyStatsAsync(symbol).Result; CompanyYF company = new CompanyYF { Symbol = symbol, Exchange = "OTC", Stats = stats }; companies.SymbolsToCompanies.Add(symbol, company); } } } string otcMarketsData = Companies.GetFromUri(Companies.OtcMarketsUri); string[] otcMarketsDataLines = otcMarketsData.Split(new[] { Environment.NewLine }, StringSplitOptions.None); for (int k = 1; k < otcMarketsDataLines.Length; k++) //trim first row { string line = otcMarketsDataLines[k]; string[] data = line.Split(','); if (data.Count() > 3) { string symbol = data[0]; if (!companies.SymbolsToCompanies.ContainsKey(symbol) && !String.IsNullOrEmpty(symbol)) { CompanyStatsYF stats = YahooFinance.GetCompanyStatsAsync(symbol).Result; CompanyYF company = new CompanyYF { Symbol = symbol, Exchange = data[2], Stats = stats }; companies.SymbolsToCompanies.Add(symbol, company); } } } return(await Task.FromResult(companies)); }