/// <summary> /// This gathers the last Ten Days of a Symbol Price History by minute and combines it with previously stored data. /// It rights the combined results to the TradeData folder /// </summary> /// <param name="client">HttpClient with OAuth Header</param> /// <param name="apiKey">TDAmeritrade API Application Key</param> /// <param name="symbol">Market (Stock) Symbol Case Sensitive</param> /// <param name="historyPath">Program Data Path (Configurable)</param> /// <param name="deleteAllFilesOtherThenNewAndSourceofTruth">If true after combining all the data files /// attempt to delete all the files except for the previously source of true and the newly combined price history. /// Unfortunately if there are not new updates to the price history it deletes all previous sources of truth</param> /// <returns>The new combined file path</returns> public static string UpdateStockByMinuteHistoryFile(HttpClient client, string apiKey, string symbol, string historyPath, bool deleteAllFilesOtherThenNewAndSourceofTruth = false) { //Get Latest by Minute data string newStorageFile = Gather10daysByTheMinute(client, apiKey, symbol, historyPath); //Get Files to Combine string storageFolderPath = getSymbolsPriceHistoryPath(historyPath, symbol, "ByMinute"); List <QuoteFile> priceByMinuteFiles = ReadWriteJSONToDisk.getQuotesFileListFromDirectory(storageFolderPath); //Combine Files List <Quote> NewQuoteList = new List <Quote>(); foreach (QuoteFile file in priceByMinuteFiles) { List <Quote> filesQuotes = ReadWriteJSONToDisk.getQuotesFromJSON(file.path); NewQuoteList = CombineQuoteLists(NewQuoteList, filesQuotes); } //write quoteList string quoteFileName = getFileNameForPriceHistory(NewQuoteList, true); string saveFilePath = $"{storageFolderPath}\\{quoteFileName}"; //save File ReadWriteJSONToDisk.writeDataAsJSON(saveFilePath, NewQuoteList); //delete old files if (deleteAllFilesOtherThenNewAndSourceofTruth) { QuoteFile oldSourceOfTruth = ChooseSourceOfTruthFile(priceByMinuteFiles); List <QuoteFile> filesToDelete = priceByMinuteFiles.Where(q => q.info.Name != oldSourceOfTruth.info.Name).ToList(); int filesDeleted = ReadWriteJSONToDisk.deleteFiles(filesToDelete); } //return new file path return(saveFilePath); }
public virtual QuoteFile CreateRandomFile(Identifiers allowedIdentifiers, int lineCount) { var quoteFile = new QuoteFile(); var randomQuotes = this.QuoteFactory.CreateListOfRandomQuotes(allowedIdentifiers, lineCount); quoteFile.AddRange(randomQuotes); return quoteFile; }
public virtual QuoteFile CreateRandomFile(Identifiers allowedIdentifiers, int lineCount) { var quoteFile = new QuoteFile(); var randomQuotes = this.QuoteFactory.CreateListOfRandomQuotes(allowedIdentifiers, lineCount); quoteFile.AddRange(randomQuotes); return(quoteFile); }
/// <summary> /// Attempts to pick the file that goes back the farthest and contains the most data from a list of QuoteFiles /// </summary> /// <param name="files">Quote Files (pertaining to a specific symbol at a specific frequency</param> /// <returns></returns> public static QuoteFile ChooseSourceOfTruthFile(List <QuoteFile> files) { string firststartDate = files.Select(s => s.startDate).Min(); List <QuoteFile> filesWithMinStartDate = files.Where(q => q.startDate == firststartDate).ToList(); if (filesWithMinStartDate.Count == 1) { return(filesWithMinStartDate.First()); } QuoteFile returnFile = files.OrderByDescending(o => o.info.Length).First(); return(returnFile); }