private static void QuandlSequentialScrape() { var api = new QuandlApi(); List<Company> companies = new List<Company>(); var scraped = new List<string>(); using (var db = new CapstoneContext()) { companies = db.Companies.ToList(); scraped = db.QStockPrices.GroupBy(p => p.CompanyId).Select(p => p.Key).ToList(); } foreach (var company in companies) { using (var db = new CapstoneContext()) { scraped = db.QStockPrices.GroupBy(p => p.CompanyId).Select(p => p.Key).ToList(); } if (!scraped.Contains(company.StockId)) { api.ScrapeAllPrice(company.StockId); } else { Console.WriteLine(company.StockId + " FINISHED"); } } }
public ActionResult Index() { var db = new CapstoneContext(); var model = db.QStockPrices.GroupBy(q => q.CompanyId).Select(g => g.Key); return View(model); }
// // GET: /Company/ public ActionResult Details() { var symbol = Request["symb"].ToString(); var context = new CapstoneContext(); var model = context.Companies.Find(symbol); return View(model); }
public ActionResult Index(StockViewModel model) { if (model.Search != null) { CapstoneContext context = new CapstoneContext(); model.Company = context.Companies.FirstOrDefault(c => c.StockId == model.Search); } return View(model); }
public ActionResult Index(string id) { CapstoneContext context = new CapstoneContext(); StockViewModel model = new StockViewModel(); if (!string.IsNullOrEmpty(id)) { model.Company = context.Companies.FirstOrDefault(c => c.StockId == id); } return View(model); }
public ActionResult GetSymbol() { var symbol = Request["symb"].ToString(); var db = new CapstoneContext(); var company = db.Companies.FirstOrDefault(e => e.StockId.Equals(symbol, StringComparison.OrdinalIgnoreCase)); if (company != null) { @ViewBag.Response = company.CompanyName; } else { @ViewBag.Response = "Cannot find company"; } return View("Index"); }
private static void SaveBingNews() { var bingSearch = new BingSearchApi(); //a.Query("AAPL"); List<Company> companies = new List<Company>(); using (var db = new CapstoneContext()) { companies = db.Companies.ToList(); } foreach (var company in companies) { var results = bingSearch.Query(company.CompanyName). Select( news => { return new BingNews() { Id = news.ID, Title = news.Title, Url = news.Url, Source = news.Source, Description = news.Description, Date = news.Date, CompanyId = company.StockId }; }); foreach (var entry in results) { using (var db = new CapstoneContext()) { db.BingNews.Add(entry); db.SaveChanges(); } } } }
private static void scrapOneCompany() { var api = new QuandlApi(); List<Company> companies = new List<Company>(); var scraped = new List<string>(); using (var db = new CapstoneContext()) { companies = db.Companies.ToList(); scraped = db.QStockPrices.GroupBy(p => p.CompanyId).Select(p => p.Key).ToList(); } var com = companies.First(c => !(scraped.Contains(c.StockId))); api.ScrapeAllPrice(com.StockId); Console.WriteLine("Finished"); Console.ReadLine(); }
// Example call https://www.quandl.com/api/v1/datasets/WIKI/AAPL.csv?sort_order=asc&exclude_headers=true&rows=3&trim_start=2012-11-01&trim_end=2013-11-30&column=4&collapse=quarterly&transformation=rdiff // https://www.quandl.com/api/v1/datasets.json?query=crude+oil // https://www.quandl.com/api/v1/datasets/WIKI/AAPL.json public void ScrapeAllPrice(string companySymbol) { string apiUrl = string.Format("{0}datasets/WIKI/{1}.json?auth_token={2}", Url, companySymbol, APIKey); var jsonResponseString = GET(apiUrl); var jsonResponse = JsonConvert.DeserializeObject<QuandlJsonResponse>(jsonResponseString); var data = jsonResponse.Data; foreach (var entry in data) { if (entry.Length == 13) { QuandlStockPrice price = new QuandlStockPrice() { CompanyId = companySymbol, Date = DateTime.Parse(entry[0].ToString()), Open = (double?)entry[1], High = (double?)entry[2], Low = (double?)entry[3], Close = (double?)entry[4], Volume = (double?)entry[5], ExDividend = (double?)entry[6], SplitRatio = (double?)entry[7], AdjOpen = (double?)entry[8], AdjHigh = (double?)entry[9], AdjLow = (double?)entry[10], AdjClose = (double?)entry[11], AdjVolume = (double?)entry[12] }; using (var db = new CapstoneContext()) { try { db.QStockPrices.Add(price); db.SaveChanges(); Console.WriteLine(companySymbol + " " + price.Date.ToShortDateString()); } catch { Console.WriteLine("FAILED!! " + companySymbol + " " + price.Date.ToShortDateString()); } } } else { throw new Exception(); } } }
public void SaveCompanyList(List<Company> companies) { foreach (var c in companies) { using (var db = new CapstoneContext()) { db.Companies.Add(c); db.SaveChanges(); } Console.WriteLine(c.StockId); } }