/// <summary>
        /// Checks the database for the last date downloaded and sets the start date string. This allows the program to be flexible to weekends and holidays.
        /// Additionally the method allows the program to retreive data that may not have been available previously.
        /// </summary>
        /// <param name="now"></param>
        /// <param name="transactions"></param>
        /// <param name="peregrine"></param>
        /// <param name="stock"></param>
        /// <returns></returns>
        public string DateSelect(DateTime date, Transactions transactions, PeregrineOperation peregrine, string stock)
        {
            List <DateTime> latestDate = transactions.DatabaseDateQuery(stock);

            try
            {
                string startDate;
                if (date.Date.AddDays(-100) > latestDate[0])
                {
                    startDate = date.AddDays(-100).ToShortDateString(); // if there is greater than 100 day gap the start is set to 100 days.
                }
                else if (latestDate == null)
                {
                    startDate = date.AddDays(-100).ToShortDateString();
                }
                else
                {
                    startDate = latestDate[0].AddDays(1).ToShortDateString();
                }
                return(startDate);
            }
            catch (ArgumentOutOfRangeException)
            {
                Console.WriteLine($"There was a problem with {stock} it was skipped");
                string startDate = date.AddDays(-100).ToShortDateString();

                return(startDate);
            }

            // Add Try - Catch to deal with stock not found.
        }
        /// <summary>
        /// Downloads a single stock, verifies contents. If there is valid data the data is saved to the data base
        /// and the table containing the Clean Data list is updated.
        /// </summary>
        /// <param name="numberDays"></param>
        /// <param name="stock"></param>
        public void ToDatabase(DateTime date, Formatting formatting, PeregrineOperation peregrine, Transactions transactions, WebClient web, WebURIs uRIs, string stock, string Database)
        {
            string startDate = DateSelect(date, transactions, peregrine, stock); // customizes start date to the last date downloaded defaults with 100 days of data

            //int benchMark = tradingDays(startDate, web, uRIs, date); // number of rows that should be in a valid data set.


            string stockData = HistoricalDataDownload(stock, startDate, web, uRIs, date, peregrine, transactions); // downloads historical data as a string.
                                                                                                                   // int actualData = cleanData(stockData); // passes data to check the quantity of data.
            var DailyStockData = formatting.CSVFileParse(stockData, stock);

            transactions.SaveToTableStockPrices(DailyStockData);

            transactions.SaveToCleanData(stock); // write clean list to Table
        }
        static void Main(string[] args)
        {
            //DateTime date = DateTime.Now;
            //DownloadEngine download = new DownloadEngine();
            //Formatting formatting = new Formatting();
            //MACD macd = new MACD();
            //Stochastic stochastic = new Stochastic();
            //TechnicalIndicators indicators = new TechnicalIndicators();
            //Transactions transactions = new Transactions();
            //WebClient web = new WebClient(); // provides the ability to download from the internet
            //WebURIs uRIs = new WebURIs(); // refers to an instance of the Wall Street Journal URL
            PeregrineOperation peregrine = new PeregrineOperation();

            //string stockData = web.DownloadString(uRIs.WSJHistorical("A", "02/09/2019", "06/12/2019")); // method call to retrieve the data

            //Console.WriteLine(stockData);
            peregrine.Run("09:22:00");
        }
Esempio n. 4
0
        public List <MACD> TodaysMACD(string stock, Transactions transactions)
        {
            PeregrineOperation peregrine = new PeregrineOperation();
            List <double>      Close     = transactions.DatabasePriceQuery(peregrine.Database, stock, "Close"); // returns data with most recent date at Nth index
            List <double>      EMA12     = EMA(Close, 12);
            List <double>      EMA26     = EMA(Close, 26);
            List <double>      macd      = StarterMACD(stock, EMA12, EMA26, Close, transactions);
            List <double>      signal    = MACD_Signal(macd);


            // List creating the MACD object
            List <MACD> MACDList = new List <MACD>()
            {
                new MACD {
                    MACDValue = macd[0], MACDSignal = signal[signal.Count - 1],
                    EMA12     = EMA12[0], EMA26 = EMA26[0]
                }
            };

            return(MACDList);
        }
        /// <summary>
        /// Downloads daily historical stock data.
        /// </summary>
        public string HistoricalDataDownload(string stock, string startDate, WebClient web, WebURIs uRIs, DateTime date, PeregrineOperation peregrine, Transactions transactions)
        {
            string endDate = date.ToShortDateString();

            string stockData = web.DownloadString(uRIs.WSJHistorical(stock, startDate, endDate)); // method call to retrieve the data

            return(stockData);
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            PeregrineOperation peregrine = new PeregrineOperation();

            peregrine.Run();
        }