/// <summary> /// Populate the Nasdaq combox so that we have a list of nasdaq companies to choose from /// </summary> private void populateNasdaqComboBox() { aStock nasdaq = new aStock(); string url = "http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NASDAQ&render=download"; //Save nasdaq information to the computer nasdaq.ReadFromURL(url); //Populate the ticker combobox string nasdaqFilePath = @"C:\DEV\STOCKDATA\NASDAQ\companylist.csv"; string[] lines = File.ReadAllLines(nasdaqFilePath); string removeHeader = "\"Symbol\",\"Name\",\"LastSale\",\"MarketCap\",\"ADR TSO\",\"IPOyear\",\"Sector\",\"Industry\",\"Summary Quote\","; string removeWhiteSpace = ""; lines = lines.Where(val => val != removeHeader).ToArray(); lines = lines.Where(val => val != removeWhiteSpace).ToArray(); foreach (var line in lines) { string[] ticker = line.Split(',', '"'); cbCompanyTicker.Items.Add(ticker[1]); } }
/// <summary> /// Submit button to get query based on the user options provided in the form /// </summary> private void btnSubmit_Click(object sender, EventArgs e) { aStock stock = new aStock(resolution, startingDate, endingDate, ticker); if (rbOnline.Checked == true) { // clear list view lsvStock.Items.Clear(); //************************************ //Pull from yahoo and save to computer //************************************ // create url from ticker information URL = createURL(ticker, resolution, startingDate.Day.ToString(), startingDate.Month.ToString(), startingDate.Year.ToString(), endingDate.Day.ToString(), endingDate.Month.ToString(), endingDate.Year.ToString()); // return data from Yahoo query url stock.ReadFromURL(URL); // populate list view with data! // read from file List <aCandlestick> stockInformation = stock.ReadFromFile(ticker); // read somewhere that this helps with speed // http://stackoverflow.com/questions/9008310/how-to-speed-adding-items-to-a-listview lsvStock.BeginUpdate(); foreach (var line in stockInformation) { // add each element as a list view item (subitem) ListViewItem element = new ListViewItem(line.StartingDate.ToShortDateString()); // date element.SubItems.Add(line.Open.ToString()); //open element.SubItems.Add(line.High.ToString()); //high element.SubItems.Add(line.Low.ToString()); //low element.SubItems.Add(line.Close.ToString()); //close element.SubItems.Add(line.Volume.ToString()); //volume lsvStock.Items.Add(element); } // stop updating list view lsvStock.EndUpdate(); // auto resize columns for (int i = 0; i < lsvStock.Columns.Count - 1; i++) { lsvStock.AutoResizeColumn(i, ColumnHeaderAutoResizeStyle.ColumnContent); } // show list view lsvStock.Visible = true; // tell user the data has been downloaded //MessageBox.Show("Data from " + ticker + " was downloaded!"); } else if (rbDisplay.Checked == true) { List <aCandlestick> stockInformation = stock.ReadFromFile(ticker); CandlestickForm modelessWindow = new CandlestickForm(stockInformation, ticker, resolution, startingDate, endingDate); modelessWindow.Show(); } }