コード例 #1
0
        /// <summary>
        /// Updates the price history for all tickers in the database.
        /// </summary>
        private void UpdateAllTickers()
        {
            List<Stock> stocks;
            using (var context = new StockScreenerEntities())
            {
                stocks = context.Stocks.ToList();
            }

            var dataUpdater = new DataUpdater();
            dataUpdater.UpdateTickerHistories(stocks);

            Console.ReadLine();
        }
コード例 #2
0
        /// <summary>
        /// Updates the price history for tickers in a watch list.
        /// </summary>
        private void UpdateTickersInWatchList()
        {
            // First, print a list of watch lists for the user to choose from.
            this.DisplayWatchLists();

            // Prompt the user to select the watch list that will be updated with new data.
            Console.Write("Select ID of watch list to update. ([Blank] to cancel.) -->  ");
            var input = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(input))
            {
                // The user opted to cancel without entering an ID.
                Console.WriteLine();
                return;
            }

            int id;
            if (!int.TryParse(input, out id))
            {
                // Invalid Input -- non-numeric data!!!
                Console.WriteLine("Invalid input...no watch list was updated.");
                Console.WriteLine();
                return;
            }

            using (var context = new StockScreenerEntities())
            {
                var watchLists = context.Watchlists.ToList();

                if (watchLists.Count(list => list.ID == id) <= 0)
                {
                    // Invalid Input -- invalid Watch List ID!!!
                    Console.WriteLine("Invalid input...no watch list was upated.");
                    Console.WriteLine();
                }
                else
                {
                    // Valid Input -- Update the selected watch list.
                    var dataUpdater = new DataUpdater();
                    dataUpdater.UpdateTickerHistories(watchLists.First(list => list.ID == id).Stocks);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Repopulates the list of tickers in the database from the CSV files downloaded from NASDAQ's website.
        /// </summary>
        private void RepopulateTickersInDatabase()
        {
            const string NyseFile = @"TickerLists\NyseCompanyList.csv";
            const string NasdaqFile = @"TickerLists\NasdaqCompanyList.csv";

            if (!File.Exists(NyseFile))
            {
                Console.WriteLine("Error!  Cannot find the file containing the list of NYSE stocks (" + NyseFile + ").");
                Console.WriteLine("No tickers were updated.");
                Console.WriteLine();
                return;
            }

            if (!File.Exists(NasdaqFile))
            {
                Console.WriteLine("Error!  Cannot find the file containing the list of NASDAQ stocks (" + NasdaqFile + ").");
                Console.WriteLine("No tickers were updated.");
                Console.WriteLine();
                return;
            }

            // Create a list of stocks currently listed on the NYSE and NASDAQ
            var currentStocks = this.ReadStockListForExchange("NYSE", NyseFile);
            currentStocks.AddRange(this.ReadStockListForExchange("NASDAQ", NasdaqFile));

            // Update the database with the list of current stocks.
            var dataUpdater = new DataUpdater();
            dataUpdater.MakeDbStockListCurrent(currentStocks);
        }