/// <summary> /// Main entry point for the class. Downloads all data for all symbols in a list /// </summary> /// <returns>Task - not used</returns> public async Task DownloadDataFromListAsync() { FileInfo symbolFileInfo = new FileInfo(SymbolList); if (!symbolFileInfo.Exists) { throw new FileNotFoundException(symbolFileInfo.FullName); } // Build a list of symbols from the symbol file var symbolList = new SymbolListBuilder().BuildListFromFile(symbolFileInfo); // use a dummy symbol to create the object _uriBuilder = new DownloadURIBuilder(Exchange, "A"); await LoopSymbolList(symbolList); }
public string GetExchangeForSymbol(string symbol) { var builder = new DownloadURIBuilder("", symbol); DateTime startdate = DateTime.Now.AddDays(-2); DateTime enddate = DateTime.Now.AddDays(-1); string uri = builder.GetGetPricesUrlForRecentData(startdate, enddate); WebClient wClient = new WebClient(); NameValueCollection myQueryStringCollection = new NameValueCollection(); myQueryStringCollection.Add("symbol", _symbol); wClient.QueryString = myQueryStringCollection; string result = wClient.DownloadString(uri); string exchange = result.Substring(11, result.IndexOf("\n", System.StringComparison.Ordinal) - 11); return exchange; }
public string GetExchangeForSymbol(string symbol) { var builder = new DownloadURIBuilder("", symbol); DateTime startdate = DateTime.Now.AddDays(-2); DateTime enddate = DateTime.Now.AddDays(-1); string uri = builder.GetGetPricesUrlForRecentData(startdate, enddate); WebClient wClient = new WebClient(); NameValueCollection myQueryStringCollection = new NameValueCollection(); myQueryStringCollection.Add("symbol", _symbol); wClient.QueryString = myQueryStringCollection; string result = wClient.DownloadString(uri); string exchange = result.Substring(11, result.IndexOf("\n", System.StringComparison.Ordinal) - 11); return(exchange); }
/// <summary> /// Gets teh Url from the Builder /// </summary> /// <returns>string - the url calculated in the Builder</returns> private string getDownloadURI() { string ticker = textBoxTicker.Text; string exchange = textBoxExchange.Text; if (String.IsNullOrEmpty(ticker)) { return string.Empty; } DownloadURIBuilder uriBuilder = new DownloadURIBuilder(exchange, ticker); if (radioButtonAllData.Checked) { return uriBuilder.GetGetPricesUrlToDownloadAllData(DateTime.Now); } else if (radioButtonLastQuoute.Checked) { return uriBuilder.GetGetPricesUrlForLastQuote(); } else if (radioButtonSince.Checked) { DateTime startDate = dateTimePickerSinceDate.Value.Date, endDate = DateTime.Now.Date; if (endDate < startDate) { //It's impossible to download data from the future. That's why no URL is returned in this case. return string.Empty; } else { return uriBuilder.GetGetPricesUrlForRecentData(startDate, endDate); } } else if (radioButtonMinutes.Checked) { return uriBuilder.GetGetPricesUrlForLastNumberOfDays(15); } else { return string.Empty; } }
/// <summary> /// Entry point for downloading data from a list /// </summary> /// <returns>nothing</returns> public async Task DownloadDataFromListAsync() { FileInfo symbolFileInfo = new FileInfo(SymbolList); if (!symbolFileInfo.Exists) { throw new FileNotFoundException(symbolFileInfo.FullName); } // Build a list of symbols from the symbol file var symbolList = new SymbolListBuilder().BuildListFromFile(symbolFileInfo); // use a dummy symbol to create the object _uriBuilder = new DownloadURIBuilder(Exchange, "A"); if (_wClient == null) { _wClient = new WebClient(); _wClient.DownloadDataCompleted += wClient_DownloadDataCompleted; } await LoopSymbolList(symbolList); }
/// <summary> /// Reads JJs symbols.txt and checks to see if the zip files exist. /// </summary> /// <param name="symbolFileInfo"></param> /// <returns>true if they all do</returns> public static bool CheckJJList(FileInfo symbolFileInfo) { List <string> noexchange = new List <string>(); Dictionary <string, string> symbolDictionary = new Dictionary <string, string>(); //SymbolListBuilder builder = new SymbolListBuilder(); string symbols = string.Empty; using (StreamReader sr = new StreamReader(symbolFileInfo.FullName)) { try { while (!sr.EndOfStream) { string symbol = sr.ReadLine(); if (!string.IsNullOrEmpty(symbol)) { symbolDictionary.Add(symbol, ""); } } } catch (Exception ex) { Console.WriteLine("The file could not be read:"); Console.WriteLine(ex.Message); } } var uriBuilder = new DownloadURIBuilder("NYSE", "AAMRQ"); foreach (var ticker in symbolDictionary) { uriBuilder.SetTickerName(ticker.Key); uriBuilder.SetExchangeName(ticker.Value); var uri = uriBuilder.GetGetPricesUrlToDownloadAllData(DateTime.Now); var wClient = new WebClient(); byte[] buf = wClient.DownloadData(uri); string rstring = Encoding.Default.GetString(buf); bool found = false; if (rstring.Length > 0) { string[] lines = rstring.Split('\n'); foreach (string line in lines) { if (line.StartsWith("a")) { found = true; break; } } if (!found) { noexchange.Add(ticker.Key); } } } // deletes any old bad csv files and writes new ones SaveBadSymbolList(new FileInfo(symbolFileInfo.FullName.Replace("txt", "csv")), noexchange); if (noexchange.Count > 0) { System.Diagnostics.Debug.WriteLine("There were bad symbols in JJs List"); return(false); } return(true); }