Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
        public void orderBuys(BuyOrder[] buyorders)
        {
            BuyOrder highest = null;
            int      mecase  = 0;

            while (mecase < buyorders.Length)
            {
                int index = mecase;
                highest = buyorders[mecase];
                for (int i = mecase; i < buyorders.Length; ++i)
                {
                    if (buyorders[i] != null)
                    {
                        if (highest.getPrice() < buyorders[i].getPrice())
                        {
                            highest = buyorders[i]; index = i;
                        }
                    }
                }

                buyorders[index]  = buyorders[mecase];
                buyorders[mecase] = highest;
                ++mecase;
            }
        }
Exemplo n.º 3
0
 public BuyOrder(BuyOrder j)
 {
     this.date       = j.date;
     this.orderSize  = j.orderSize;
     this.orderPrice = j.getPrice();
 }