Exemplo n.º 1
0
        /// <summary>
        /// Gets the historic prices for a stock
        /// </summary>
        /// <param name="stock">The stock to collect prices for</param>
        /// <param name="lastRetrieveDate">The date last retrieved</param>
        private void GetPricesForStock(Stock stock, DateTime lastRetrieveDate)
        {
            List <DailyPrice> historicPrices = this.yahooHistoricWebStockEngine.Fetch(stock, lastRetrieveDate);

            using (StockBanditDataContext dataContext = new StockBanditDataContext())
            {
                // If different add to queue.
                foreach (DailyPrice dailyPrice in historicPrices)
                {
                    // Find price for today
                    DailyPrice existingPrice =
                        dataContext.DailyPrices.FirstOrDefault(
                            p => p.Date == dailyPrice.Date && p.StockCode == stock.StockCode);
                    if (existingPrice != null)
                    {
                        existingPrice.High          = dailyPrice.High;
                        existingPrice.Low           = dailyPrice.Low;
                        existingPrice.Open          = dailyPrice.Open;
                        existingPrice.Close         = dailyPrice.Close;
                        existingPrice.Volume        = dailyPrice.Volume;
                        existingPrice.AdjustedClose = dailyPrice.AdjustedClose;
                    }
                    else
                    {
                        dataContext.DailyPrices.InsertOnSubmit(dailyPrice);
                    }

                    dataContext.SubmitChanges();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reset the stock silence flags so it is checked again
        /// </summary>
        /// <param name="stock">The stock to reset</param>
        private void ResetStockSilenceFlags(Stock stock)
        {
            using (StockBanditDataContext dataContext = new StockBanditDataContext())
            {
                Stock dalStock = dataContext.Stocks.Single(s => s.StockCode == stock.StockCode);
                dalStock.Silenced      = false;
                dalStock.LastAlertTime = null;
                dataContext.SubmitChanges();

                stock.Silenced      = false;
                stock.LastAlertTime = null;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Silence a stock when it have alerted
        /// </summary>
        /// <param name="stock">The stock to silence</param>
        private void SilenceStock(Stock stock)
        {
            using (StockBanditDataContext dataContext = new StockBanditDataContext())
            {
                Stock dalStock = dataContext.Stocks.Single(s => s.StockCode == stock.StockCode);
                dalStock.Silenced      = true;
                dalStock.LastAlertTime = DateTime.Now;
                dataContext.SubmitChanges();

                stock.Silenced      = true;
                stock.LastAlertTime = DateTime.Now;
            }
        }