public void Run(string downloadTime) { DateTime date = DateTime.Now; DownloadEngine download = new DownloadEngine(); Formatting formatting = new Formatting(); PeregrineOperation peregrine = new PeregrineOperation(); 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 DownloadTimer(download, formatting, peregrine, macd, stochastic, indicators, transactions, web, uRIs, Database, downloadTime); }
/// <summary> /// The Trading Days method allows the program to validate if the file being downloaded holds the correct amount of data. I am using five of the largest /// stocks which are heavily tracked. It is unlikely that there will not be historical data on these five stocks, making them a good bench mark. /// </summary> /// <param name="numberDays"></param> /// <returns></returns> private int tradingDays(string startDate, WebClient web, WebURIs uRIs, DateTime date) { List <string> FAANG = new List <string> { "FB", "AAPL", "AMZN", "NFLX", "GOOGL" }; // Top Tech stocks: Facebook, Apple, Amazon, NetFlix, Google int count = 0; // count of the total trading days recorded for FAANG over the period. foreach (var item in FAANG) { // (website location (stock requested, startdate, enddate) splitting by the return symbol > places it into an array > counts the array elements int rows = web.DownloadString(uRIs.WSJHistorical(item, startDate, date.ToShortDateString())).Split('\n').ToArray().Count(); count += rows; // count = count(current) + rows } int tradingDays = count / 5; return(tradingDays); }
/// Download and save to Database private void Download(DateTime date, DownloadEngine download, Formatting formatting, PeregrineOperation peregrine, MACD macd, Stochastic stochastic, TechnicalIndicators indicators, Transactions transactions, WebClient web, WebURIs uRIs, string Database) { List <string> Symbols = transactions.DatabaseSymbolListQuery(Database, stocks); transactions.TruncateStockTable(Database, "Clean Data"); // clears data from the clean data table. int count = 1; foreach (var stock in Symbols) { Console.Clear(); Console.WriteLine($"Downloading {stock} || {count} of {Symbols.Count}"); download.ToDatabase(date, formatting, peregrine, transactions, web, uRIs, stock, Database); count++; } Console.WriteLine("I'm Done"); //count = 1; //calls the list of stocks that have been data verified //List<string> CleanData = transactions.DatabaseSymbolListQuery(Database, stocks); //foreach (var stock in CleanData) //{ // Console.Clear(); // Console.WriteLine($"Doing Math {stock} || {count} of {CleanData.Count}"); // List<Results> results = MathPredictsTheFuture(download, macd, stochastic, transactions, indicators, stock); // transactions.SaveToTableResult(Database, results); // saves the calculations to the Results table in the database // count++; //} //// calls the stocks from the results list //List<PeregrineResults> todaysResults = transactions.DailyResultsQuery(peregrine.Database); //transactions.TruncateStockTable(database, peregrineresults); // clears the web results table. This table feeds the model for the ASP.Net interface. //transactions.SaveToTableWebResult(peregrine.Database, todaysResults); //Console.WriteLine("Peregrine Results Updated"); }
private void DownloadTimer(DownloadEngine download, Formatting formatting, PeregrineOperation peregrine, MACD macd, Stochastic stochastic, TechnicalIndicators indicators, Transactions transactions, WebClient web, WebURIs uRIs, string Database, string downloadTime) { var DailyTime = downloadTime; //Time when method needs to be called var timeParts = DailyTime.Split(new char[1] { ':' }); var dateNow = DateTime.Now; var date = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, int.Parse(timeParts[0]), int.Parse(timeParts[1]), int.Parse(timeParts[2])); TimeSpan ts; if (date > dateNow) { ts = date - dateNow; } else { date = date.AddDays(1); ts = date - dateNow; } while (date != dateNow) { Console.WriteLine($"Waiting for {downloadTime}"); //waits certan time and run the code Task.Delay(ts).ContinueWith((x) => Download(date, download, formatting, peregrine, macd, stochastic, indicators, transactions, web, uRIs, Database)); Console.Read(); } }
/// <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); }
/// <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 }