private List <StockListObjectData> GetStockPrices(ConfigSettingsObject settings) { List <StockListObjectData> toReturn = new List <StockListObjectData>(); // To array creates a copy of the list, so that alteration withing the UI // doesn't cause forloop iteration problems whilst altering foreach (var stock in settings.watchedStock.ToArray()) { try { StockListObjectData newData = IEXHelper.GetStockData(stock, settings.iexCloudApiKey); if (settings.onlyPopupDuringTradingHours == true) { if (newData.StockStockMarketOpen == true) { toReturn.Add(newData); } } else { toReturn.Add(newData); } } catch (Exception ex) { if (ex.Message.StartsWith("Invalid status response:")) { //Invalid symbol likely Debug.WriteLine(stock + ":" + ex.Message); } else { throw ex; } } } return(toReturn); }
/// <summary> /// Called upon startup to load from file /// </summary> private void LoadSettingsFromFile() { if (File.Exists("settingsConfig.xml")) { settings = DeSerializeObject <ConfigSettingsObject>("settingsConfig.xml"); } else { // No settings config exists, so we will populate the settings with some default values settings = new ConfigSettingsObject(); settings.onlyPopupDuringTradingHours = false; settings.popupDurationSeconds = 5; settings.popupFrequencySeconds = 60; settings.iexCloudApiKey = "YOUR KEY HERE"; settings.watchedStock = new List <string>() { "AAPL", "TWTR", "K", "T" }; SaveSettingsToFile(); } // Now we have the settings file, we can have it load the settings into the config form. LoadSettingsIntoConfigForm(); }