示例#1
0
        public void UpdateStock(string stockSymbol)
        {
            //
            // Ensure that there is a valid Stock in the DB
            //
            var stock = QueryStock (stockSymbol);
            if (stock == null) {
                stock = new Stock { Symbol = stockSymbol };
                Insert (stock);
            }

            //
            // When was it last valued?
            //
            var latest = QueryLatestValuation (stock);
            var latestDate = latest != null ? latest.Time : new DateTime (1950, 1, 1);

            //
            // Get the latest valuations
            //
            try {
                var newVals = new YahooScraper ().GetValuations (stock, latestDate + TimeSpan.FromHours (23), DateTime.Now);
                foreach (var v in newVals) {
                    Insert (v);
                }
            } catch (System.Net.WebException ex) {
                Console.WriteLine (ex);
            }
        }
示例#2
0
        public void UpdateStock(string stockSymbol)
        {
            //
            // Ensure that there is a valid Stock in the DB
            //
            var stock = QueryStock(stockSymbol);

            if (stock == null)
            {
                stock = new Stock {
                    Symbol = stockSymbol
                };
                Insert(stock);
            }

            //
            // When was it last valued?
            //
            var latest     = QueryLatestValuation(stock);
            var latestDate = latest != null ? latest.Time : new DateTime(1950, 1, 1);

            //
            // Get the latest valuations
            //
            try {
                var newVals = new YahooScraper().GetValuations(stock, latestDate + TimeSpan.FromHours(23), DateTime.Now);
                foreach (var v in newVals)
                {
                    Insert(v);
                }
            } catch (System.Net.WebException ex) {
                Console.WriteLine(ex);
            }
        }
示例#3
0
        public void UpdateStock(string stockSymbol)
        {
            var stock = new Stock {
                Symbol = stockSymbol
            };

            try
            {
                var valuations = new YahooScraper().GetValuations(stock, DateTime.Now.AddYears(1), DateTime.Now).ToList();

                BeginTransaction();

                foreach (var valuation in valuations)
                {
                    Execute("INSERT INTO VALUATION (ID, STOCKID, Price) VALUES(@Param1, @Param2, @Param3);", new object[] { Guid.NewGuid().ToString(), valuation.StockId, valuation.Price });
                }

                Commit();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }