/// <summary> /// Load Index information /// </summary> private void LoadIndex() { try { StockSticker indexItem = StockList.Where(x => x.Symbol.Equals("^DJI")).SingleOrDefault(); if (indexItem != null) { lblIndex1Value.Text = String.Format("{0:F2}", indexItem.Price); lblChange1.Text = String.Format("{0:F2}", indexItem.Change); if (indexItem.Change < 0) { lblChange1.BackColor = Color.Red; } else if (indexItem.Change > 0) { lblChange1.BackColor = Color.LightGreen; } } indexItem = StockList.Where(x => x.Symbol.Equals("^IXIC")).SingleOrDefault(); if (indexItem != null) { lblIndex2Value.Text = String.Format("{0:F2}", indexItem.Price); lblChange2.Text = String.Format("{0:F2}", indexItem.Change); if (indexItem.Change < 0) { lblChange2.BackColor = Color.Red; } else if (indexItem.Change > 0) { lblChange2.BackColor = Color.LightGreen; } } indexItem = StockList.Where(x => x.Symbol.Equals("^GSPC")).SingleOrDefault(); if (indexItem != null) { lblIndex3Value.Text = String.Format("{0:F2}", indexItem.Price); lblChange3.Text = String.Format("{0:F2}", indexItem.Change); if (indexItem.Change < 0) { lblChange3.BackColor = Color.Red; } else if (indexItem.Change > 0) { lblChange3.BackColor = Color.LightGreen; } } } catch (Exception ex) { //log to a file as well MessageBox.Show("Unexpected error loading index details." + Environment.NewLine + ex.Message); Shutdown(); } }
private void loadPortfolio(string name) { string symbol = ""; DateTime tradedate; long shares; double costbasis; string xmlFile = "Username." + name + ".xml"; PortFolioList.Clear(); try { using (XmlReader reader = XmlReader.Create(xmlFile)) { while (!reader.EOF) { while (reader.ReadToFollowing("stock")) { reader.ReadToFollowing("symbol"); symbol = reader.ReadElementContentAsString(); tradedate = Convert.ToDateTime(reader.ReadElementString("tradedate")); shares = long.Parse(reader.ReadElementString("shares")); costbasis = Convert.ToDouble(reader.ReadElementString("costbasis")); StockSticker item = StockList.Where(x => x.Symbol == symbol.ToUpper()).SingleOrDefault(); if (item == null) { LoadStockGrid(loadQuote(symbol)); item = StockList.Where(x => x.Symbol == symbol.ToUpper()).SingleOrDefault(); } PortFolioList.Add(new PortFolio(symbol, tradedate, shares, costbasis, item)); } } this.bsPortfolio.DataSource = PortFolioList; this.grdPortfolio.DataSource = bsPortfolio; bsPortfolio.ResetBindings(false); btnPortfolio.Text = name; } } catch (Exception ex) { //log to a file as well MessageBox.Show("Unexpected error loading portfolio." + Environment.NewLine + ex.Message); Shutdown(); } }
private void LoadStockGrid(dynamic stuff) { double price = 0; double change = 0; double chg_percent = 0; string symbol = ""; string name = ""; try { foreach (var ticker in stuff) { foreach (var stock in ticker.First.resources) { symbol = (string)stock.resource.fields.symbol; name = ((string)stock.resource.fields.issuer_name).Replace("&", "&"); price = Math.Round(Double.Parse((string)stock.resource.fields.price), 2); change = Math.Round(Double.Parse((string)stock.resource.fields.change), 2); chg_percent = Math.Round(Double.Parse((string)stock.resource.fields.chg_percent), 2); StockSticker item = StockList.Where(x => x.Symbol == symbol).SingleOrDefault(); if (item != null) { item.Price = price; item.Change = change; item.ChangePercent = chg_percent; } else { StockList.Add(new StockSticker((string)stock.resource.fields.ts, symbol, name, price, change, chg_percent)); } } } } catch (Exception ex) { //log to a file as well MessageBox.Show("Unexpected error loading stock details." + Environment.NewLine + ex.Message); Shutdown(); } }
public PortFolio(string symbol, DateTime tradedate, long shares, double costbasis, StockSticker sticker) { this.TradeDate = tradedate; this.Symbol = symbol; this.Shares = shares; this.CostBasis = costbasis; this.Totalcost = shares * costbasis; this.Sticker = sticker; this.Sticker.PropertyChanged += new PropertyChangedEventHandler(Sticker_PropertyChanged); }