Ejemplo n.º 1
0
        public List<Model> ReadStockPriceFromCSV()
        {
            var result = new List<Model>();
            DownloadStockPriceFromYahoo();
            if (File.Exists(_path))
            {                
                using (var myReader = new TextFieldParser(_path))
                {
                    myReader.TextFieldType = FieldType.Delimited;
                    myReader.Delimiters = new string[] { "," };
                    string[] row;
                    while (!myReader.EndOfData)
                    {
                        try
                        {
                            row = myReader.ReadFields();
                            Model model = new Model() { 
                                                        Symbol = row[0], 
                                                        Name = row[1],                                                         
                            };
                            double lastTradePrice;
                            double.TryParse(row[2], out lastTradePrice);
                            model.LastTradePrice = lastTradePrice;

                            DateTime lastTradeDate;
                            DateTime.TryParseExact(row[3], "M/dd/yyyy", null, DateTimeStyles.None, out lastTradeDate);
                            model.LastTradeDate = lastTradeDate;

                            double openPrice;
                            double.TryParse(row[4], out openPrice);
                            model.OpenPrice = openPrice;

                            double dayHighPrice;
                            double.TryParse(row[5], out dayHighPrice);
                            model.DayHighPrice = dayHighPrice;

                            double dayLowPrice;
                            double.TryParse(row[6], out dayLowPrice);
                            model.DayLowPrice = dayLowPrice;
                            model.TradeTime = DateTime.Today.Date + new TimeSpan(8, 0, 0);
                            result.Add(model);
                        }
                        catch (MalformedLineException)
                        {
                            throw;
                        }
                    }
                }                
            }
            return result;
        }
Ejemplo n.º 2
0
 public ProductService(Model.ProductService ProductService)
 {
     _productService = ProductService;
 }
Ejemplo n.º 3
0
 public void Init()
 {
     _random = new Random();
     _service = new Service();
     _model = new Model() { Symbol = "MSFT", Name = "Microsoft Corpora", LastTradePrice = 37.575, LastTradeDate = DateTime.Now.AddDays(-1), OpenPrice = 37.65, DayLowPrice = 37.51, DayHighPrice = 37.78 };
 }