Пример #1
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);
 }
Пример #2
0
        static void writeToFile(Stream myStream, StockHistory stockhistory)
        {
            try
            {

                using ( StreamWriter sw = new StreamWriter ( myStream , System.Text.Encoding.Default ) )
                {
                    sw.WriteLine(String.Format("Symbol: {0}", stockhistory.Stock.Name));
                    sw.WriteLine(String.Format("Description: {0}", stockhistory.Stock.Description));
                    sw.WriteLine(String.Format("StartDate: {0}", stockhistory.StartDate));
                    sw.WriteLine(String.Format("EndDate: {0}", stockhistory.EndDate));

                    sw.WriteLine("Date;Volume;Open;Close;AdjustedClosingPrices;Low;High");
                    foreach (var item in stockhistory.Quotes) {

                        sw.Write ( createCSV(item));
                    }

                }
            }
            // Fehler
            catch ( Exception ex )
            {
                System.Console.WriteLine ("ERROR: " + stockhistory.Stock);
            }
        }