예제 #1
0
 /// <summary>
 /// Creates a new StockHistory
 /// </summary>
 /// <param name="myStock">The stock</param>
 /// <param name="myStartDate">The starting date</param>
 /// <param name="myEndDate">The end date</param>
 /// <param name="myQuotes">The quotes between start and end</param>
 public StockHistory(Stock myStock, DateTime myStartDate, DateTime myEndDate, IEnumerable<StockQuote> myQuotes)
 {
     Stock = myStock;
     StartDate = myStartDate;
     EndDate = myEndDate;
     Quotes = new List<StockQuote>(myQuotes);
 }
예제 #2
0
        static void Main(string[] args)
        {
            if (args.Count() != 0)
            {
                string dataDirectory = CrawlerSettings.Default.DataDirectory;
                bool overwrite = false;

                if (Directory.Exists(dataDirectory))
                {
                    if (overwrite)
                    {
                        Directory.Delete(dataDirectory, true);
                        Directory.CreateDirectory(dataDirectory);
                    }
                }
                else
                {
                    Directory.CreateDirectory(dataDirectory);
                }

                FileStream symbolFile = File.OpenRead(args[0]);

                StreamReader reader = new StreamReader(symbolFile);

                //skip first
                reader.ReadLine();

                String line = reader.ReadLine();

                Random prng = new Random();
                int counter = 0;

                while (line != null)
                {
                    counter++;

                    var stock = new Stock(line);

                    string file = dataDirectory + Path.DirectorySeparatorChar + Encode(stock.Name);

                    Console.WriteLine(String.Format("{0}:\tName:{1}, Desc:{2}", counter, stock.Name, stock.Description));

                    if (File.Exists(file))
                    {
                        if (overwrite)
                        {
                            File.Delete(file);
                            PersistStockAndHistory(stock, file);
                            Thread.Sleep(prng.Next(1000, 5000));
                        }
                    }
                    else
                    {
                        PersistStockAndHistory(stock, file);
                        Thread.Sleep(prng.Next(1000, 5000));
                    }

                    line = reader.ReadLine();
                }

                Console.WriteLine("done! <hit return>");
                Console.ReadLine();
            }
        }
예제 #3
0
 private static void PersistStockAndHistory(Stock myStock, String myFileName)
 {
     var stockHistoryFile = File.Create(myFileName);
     try
     {
         StockQuotesSharp.SerializeHistory(myStock, stockHistoryFile, DateTime.MinValue, DateTime.Now);
     }
     catch (Exception e)
     {
         Console.WriteLine(String.Format("Error while crawling history for stock {0} because of \"{1}\".", myStock.Name, e.Message));
     }
 }
예제 #4
0
 /// <summary>
 /// Serializes the history into a stream
 /// </summary>
 /// <param name="stock">The interesting stock</param>
 /// <param name="myStream">The stream in which the result should be written to</param>
 /// <param name="myFromDate">The date where the historic data should start</param>
 /// <param name="myToDate">The date where the history data should end</param>
 public static void SerializeHistory(Stock stock, Stream myStream, DateTime myFromDate, DateTime myToDate)
 {
     var stockhistory = new StockHistory(stock, myFromDate, myToDate, GetHistoricQuotes(stock.Name, myFromDate, myToDate));
     writeToFile (myStream, stockhistory);
 }