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> /// Loops through a symbol list, looking up the exchange where the security is traded /// and writing the files to an {exchange}\{firstletter}\{symbol} folder /// </summary> /// <param name="symbolList">A list of symbols</param> /// <returns>Task (void)</returns> private async Task LoopSymbolList(Dictionary <string, string> symbolList) { List <string> files = new List <string>(); foreach (string ticker in symbolList.Keys) { string symbol = ticker.Replace("^", "-").Trim(); if (ticker.Contains(@"\") || ticker.Contains(@"/")) { continue; } string outputFolder; if (OutputDirectory != null || OutputDirectory.Length > 0) { if (!OutputDirectory.EndsWith(@"\")) { OutputDirectory += @"\"; } outputFolder = OutputDirectory; // The factory addes the daily } else { outputFolder = Config.GetDefaultDownloadDirectory(); } DirectoryInfo _qcInfo = new DirectoryInfo(outputFolder); DirectoryInfo dailyDirectoryInfo = DailyDirectoryFactory.Create(_qcInfo); _uriBuilder.SetTickerName(ticker); var uri = _uriBuilder.GetGetPricesUrlToDownloadAllData(DateTime.Now); string fn = dailyDirectoryInfo.FullName + ticker.ToLower() + ".zip"; if (File.Exists(fn)) { /* to rebuild the entire list */ //File.Delete(fn); /* to add the latest files */ FileInfo f = new FileInfo(fn); DateTime lastentry = GetLastEntryDate(fn, ticker); DateTime endDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); // the routine adds a day if (lastentry.Equals(endDateTime)) { continue; } uri = _uriBuilder.GetGetPricesUrlForRecentData(lastentry.AddDays(1), endDateTime); } // download Data Ticker = ticker; WebClient wClient = new WebClient(); NameValueCollection myQueryStringCollection = new NameValueCollection(); myQueryStringCollection.Add("symbol", ticker); myQueryStringCollection.Add("OutputDirectory", dailyDirectoryInfo.FullName); wClient.QueryString = myQueryStringCollection; wClient.DownloadDataCompleted += wClient_DownloadDataCompleted; await wClient.DownloadDataTaskAsync(uri); } return; }
/// <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; } }