// 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();
                }
            }
        }
Exemple #2
0
        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();
                    }
                }
            }
        }
        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);
            }
        }