public void Update(StockMarket data) { RealtimeData stock = (RealtimeData)data; //stock.companies[2].orderSells(); //stock.companies[2].orderBuys(); SellOrder[] sellorderz = stock.companies[2].sellorders; BuyOrder[] buyorderz = stock.companies[2].buyorders; orderBuys(buyorderz); orderSells(sellorderz); for (int j = 0, i = 0; j < buyorderz.Length || i < dataGridView1.Rows.Count; ++i, ++j) { if (buyorderz[j] != null) { dataGridView1.Rows[i].Cells[0].Value = buyorderz[j].orderSize; dataGridView1.Rows[i].Cells[1].Value = buyorderz[j].getPrice(); } } for (int j = 0, i = 0; j < sellorderz.Length || i < dataGridView1.Rows.Count; ++i, ++j) { if (sellorderz[j] != null) { dataGridView1.Rows[i].Cells[2].Value = sellorderz[j].orderSize; dataGridView1.Rows[i].Cells[3].Value = sellorderz[j].getPrice(); } } }
private void MarketByOrder1_FormClosing(object sender, FormClosingEventArgs e) { Container parent = (Container)this.MdiParent; RealtimeData stock = (RealtimeData)parent.theStockMarket; stock.unregister(this); }
public void Update(StockMarket data) { RealtimeData stock = (RealtimeData)data; SellOrder[] sellorderz = stock.companies[1].sellorders; BuyOrder[] buyorderz = stock.companies[1].buyorders; int secret = 0; if (stock.companies[1].lastOrder.Equals("BuyOrder")) { BuyOrder mybuy = stock.companies[1].getLastBuyOrder(); for (int k = 0; k < dataGridView1.Rows.Count; ++k) { if (dataGridView1.Rows[k].Cells[2].Value != null && mybuy != null) { if ((float)dataGridView1.Rows[k].Cells[2].Value == (float)mybuy.getPrice()) { ++secret; dataGridView1.Rows[k].Cells[0].Value = (int)dataGridView1.Rows[k].Cells[0].Value + 1; dataGridView1.Rows[k].Cells[1].Value = (double)dataGridView1.Rows[k].Cells[1].Value + (float)mybuy.orderSize; } } } if (secret == 0 && mybuy != null) { addToViewBuy(mybuy.getPrice(), mybuy.orderSize); } secret = 0; orderBuyView(); } else { secret = 0; SellOrder mysell = stock.companies[1].getLastSellOrder(); for (int k = 0; k < dataGridView1.Rows.Count; ++k) { if (dataGridView1.Rows[k].Cells[4].Value != null && mysell != null) { if ((float)dataGridView1.Rows[k].Cells[4].Value == mysell.getPrice()) { ++secret; dataGridView1.Rows[k].Cells[5].Value = (int)dataGridView1.Rows[k].Cells[5].Value + 1; dataGridView1.Rows[k].Cells[3].Value = (double)dataGridView1.Rows[k].Cells[3].Value + mysell.orderSize; } } } if (secret == 0 && mysell != null) { addToViewSell(mysell.getPrice(), mysell.orderSize); } secret = 0; orderSellView(); } }
public void Update(StockMarket g) { RealtimeData stock = (RealtimeData)g; //verfifying for all companies SellOrder[] sellordsM = stock.companies[0].sellorders; BuyOrder[] buyordsM = stock.companies[0].buyorders; SellOrder[] sellordsA = stock.companies[1].sellorders; BuyOrder[] buyordsA = stock.companies[1].buyorders; SellOrder[] sellordsF = stock.companies[2].sellorders; BuyOrder[] buyordsF = stock.companies[2].buyorders; int index; for (index = 0; index < stock.companies.Length; ++index) { if (stock.companies[index].lastUpdated == true) { break; } } float lM; lM = verifyOrdersM(stock.companies[index].buyorders, stock.companies[index].sellorders, stock, index); double volumeM = stock.companies[index].getVolume(); if (lM != 0) { dataGridView1.Rows[index].Cells[3].Value = lM; dataGridView1.Rows[index].Cells[4].Value = (float)(lM - 35.6); float rawp = (float)((lM - 35.6) / 35.6); float percentage = (float)((float)((lM - 35.6) / 35.6) * 100); dataGridView1.Rows[index].Cells[6].Value = percentage; dataGridView1.Rows[index].Cells[7].Value = volumeM; if (rawp < 0) { Bitmap bit = new Bitmap(Properties.Resources.down); dataGridView1.Rows[index].Cells[5].Value = bit; } if (rawp == 0) { Bitmap bit = new Bitmap(Properties.Resources.noChange); dataGridView1.Rows[index].Cells[5].Value = bit; } if (rawp > 0) { Bitmap bit = new Bitmap(Properties.Resources.up); dataGridView1.Rows[index].Cells[5].Value = bit; } //add function here that does operations; } }
private void button1_Click(object sender, EventArgs e) { if (!(comboBox1.SelectedItem == null) && !(textBox1.Text.Length == 0) && !(textBox2.Text.Length == 0)) { int i = 0; string selected = this.comboBox1.GetItemText(this.comboBox1.SelectedItem); switch (selected) { case "Microsoft Corporation": date = DateTime.Now.ToString("M/d/yyyy"); orderSize = Convert.ToDouble(textBox1.Text); orderPrice = (float)Convert.ToDouble(textBox2.Text); Container parent = (Container)this.MdiParent; RealtimeData stock = (RealtimeData)parent.theStockMarket; for (i = 0; i < stock.companies.Length; ++i) { if (stock.companies[i].getName().Equals("Microsoft")) { break; } } stock.companies[i].addBuyOrder(this); stock.companies[i].lastOrder = "BuyOrder"; stock.companies[i].lastUpdated = true; for (int j = 0; j < stock.companies.Length; ++j) { if (j != i) { stock.companies[j].lastUpdated = false; } } stock.notify(); break; case "Apple Inc.": date = DateTime.Now.ToString("M/d/yyyy"); orderSize = Convert.ToDouble(textBox1.Text); orderPrice = (float)Convert.ToDouble(textBox2.Text); parent = (Container)this.MdiParent; stock = (RealtimeData)parent.theStockMarket; for (i = 0; i < stock.companies.Length; ++i) { if (stock.companies[i].getName().Equals("Apple")) { break; } } stock.companies[i].addBuyOrder(this); stock.companies[i].lastOrder = "BuyOrder"; stock.companies[i].lastUpdated = true; for (int j = 0; j < stock.companies.Length; ++j) { if (j != i) { stock.companies[j].lastUpdated = false; } } stock.notify(); break; case "Facebook": date = DateTime.Now.ToString("M/d/yyyy"); orderSize = Convert.ToDouble(textBox1.Text); orderPrice = (float)Convert.ToDouble(textBox2.Text); parent = (Container)this.MdiParent; stock = (RealtimeData)parent.theStockMarket; for (i = 0; i < stock.companies.Length; ++i) { if (stock.companies[i].getName().Equals("Facebook")) { break; } } stock.companies[i].addBuyOrder(this); stock.companies[i].lastOrder = "BuyOrder"; stock.companies[i].lastUpdated = true; for (int j = 0; j < stock.companies.Length; ++j) { if (j != i) { stock.companies[j].lastUpdated = false; } } stock.notify(); break; default: MessageBox.Show("Your company selection was incomprehensible. Please try again."); break; } } else { MessageBox.Show("Please supply empty fields"); } this.Close(); }
public float verifyOrdersM(BuyOrder[] buyords, SellOrder[] sellords, StockMarket stock, int k) { RealtimeData stocky = (RealtimeData)stock; float lastprice = 0; int initializer = 0; if (stocky.companies[k].lastOrder.Equals("SellOrder")) { int determinant = 0; for (determinant = 0; determinant < sellords.Length; ++determinant) { if (sellords[determinant] == null) { if (determinant > 0) { break; } else { return(0); } } } --determinant; for (int i = 0; i < buyords.Length; ++i) { if (buyords[i] != null) { if (sellords[determinant].orderSize == buyords[i].orderSize && sellords[determinant].getPrice() == buyords[i].getPrice()) { stocky.companies[k].setLastPrice(sellords[determinant].getPrice()); lastprice = sellords[determinant].getPrice(); ++initializer; } } } if (initializer > 0) { stocky.companies[k].successfulO.Add(sellords[determinant].orderSize); } } else if (stocky.companies[k].lastOrder.Equals("BuyOrder")) { int determinant = 0; initializer = 0; for (determinant = 0; determinant < buyords.Length; ++determinant) { if (buyords[determinant] == null) { if (determinant > 0) { break; } else { return(0); } } } --determinant; for (int i = 0; i < sellords.Length; ++i) { if (sellords[i] != null) { if (buyords[determinant].orderSize == sellords[i].orderSize && buyords[determinant].getPrice() == sellords[i].getPrice()) { stocky.companies[k].setLastPrice(buyords[determinant].getPrice()); lastprice = buyords[determinant].getPrice(); ++initializer; } } } if (initializer > 0) { stocky.companies[k].successfulO.Add(buyords[determinant].orderSize); } } return(lastprice); }