public StockSecuritiesExchange()
        {
            InitializeComponent();

            // create the intial instance of real time data, this will be passed to many other classes for use
            realTimeData = new Model_RealTimeData();
        }
Exemple #2
0
        public BidOrderForm(Model_RealTimeData RTD)
        {
            // create the windows form for placing a bid (Bid Order Form)
            InitializeComponent();

            // accept the real time data into the bid form
            this.realTimeData = RTD;
        }
        public void Update(Model_RealTimeData subject)
        {
            // this update must reset all the values in the "market depth by order" window!!

            /* The market depth by order window shows:
             *          - top 10 highest BUY prices, and the amount of shares for each
             *          - top 10 loweset SELL prices, and the amount of shares for each
             * */

            // first thing we should do is clear the view of all its data so we can reload new stuff
            this.dataGridView1.Rows.Clear();
            this.dataGridView1.Rows.Add(9);

            // first, search through the list of companies to find the company that corresponds to this observer
            foreach (Model_Company comp in subject.listOfCompanies)
            {
                // once we find the correct company
                if (this.company.companyName == comp.companyName)
                {
                    /* Create a temporary list of BuyOrders that orders the elements (using OrderBy) first by the order's price, and then (using ThenBy) by the order's
                     * DateTime. Then use reverse to get the list to be the top 10 prices */
                    List <Model_BuyOrder> BUYtemp = new List <Model_BuyOrder>(comp.buyOrdersList.OrderByDescending <Model_BuyOrder, Double>(buy => buy.OrderPrice).ThenBy <Model_BuyOrder, DateTime>(date => date.OrderDateTime));

                    /* Create a temporary list of SellOrders that orders the elements (using OrderBy) first by the order's price, and then (using ThenBy) by the order's
                     * Date Time. We don't need to use reverse here because we want the lowest sells */
                    List <Model_SellOrder> SELLtemp = new List <Model_SellOrder>(comp.sellOrdersList.OrderBy <Model_SellOrder, Double>(sell => sell.OrderPrice).ThenBy <Model_SellOrder, DateTime>(date => date.OrderDateTime));

                    // Iterate through the temporary list of buys and print the values of the top 10 highest bids
                    for (int i = 0; i < BUYtemp.Count; i++)
                    {
                        //this.dataGridView1.Rows.Add(1);
                        if (i == 10)
                        {
                            break;                                                                   // break after 10 because we only want the top 10
                        }
                        this.dataGridView1.Rows[i].Cells[0].Value = BUYtemp.ElementAt(i).OrderPrice; // this cell refers to the Buy Price column in the data grid view
                        this.dataGridView1.Rows[i].Cells[1].Value = BUYtemp.ElementAt(i).OrderSize;  // this cell refers to the Buy Volume column in the data grid view
                    }

                    // Next, iterate through all the sells and print the values of the top 10 lowest bids
                    for (int i = 0; i < SELLtemp.Count; i++)
                    {
                        if (i == 10)
                        {
                            break;                                                                    // again, break after 10 because we only want the top 10
                        }
                        this.dataGridView1.Rows[i].Cells[2].Value = SELLtemp.ElementAt(i).OrderPrice; // this cell refers to the Sell Price column in the data grid view
                        this.dataGridView1.Rows[i].Cells[3].Value = SELLtemp.ElementAt(i).OrderSize;  // this cell refers to the Sell Volume column in the data grid view
                    }
                }
            }

            // end the update method for the StockByOrder observer with an accurate representation of the top 10 highest bids and lowest sells
        }
Exemple #4
0
        public void Update(Model_RealTimeData subject)
        {
            // this update must rest all the values in the market depth by price window!!

            /* The market depth by price window shows:
             *          - the top 10 GROUPS of bids (i.e if i have 3 bids of 40, group them all
             *              together)
             *          - the total volume of the group
             *          - the total number of bids that make up that volume
             *          - same for sells, but sorted by lowest 10 values
             * */

            // first thing we should do is clear the view of all its data so we can reload new stuff
            this.dataGridView1.Rows.Clear();
            this.dataGridView1.Rows.Add(9);

            // first, search through the list of companies to find the company that corresponds to this observer
            foreach (Model_Company comp in subject.listOfCompanies)
            {
                // once we find the correct company
                if (this.company.companyName == comp.companyName)
                {
                    // First, create a temporay copy of the bid orders list so that we can group them by price
                    List <Model_BuyOrder> tempGroupedOrders = new List <Model_BuyOrder>(comp.buyOrdersList);

                    /* Use an IEnumerable type object with a template of IGrouping to create a list of groups, grouped by the order price Key. This operation
                     * also uses the order by method that orders the groups by their price (key) and reverses it to get the max orders */
                    IEnumerable <IGrouping <Double, Model_BuyOrder> > orders = tempGroupedOrders.GroupBy(buy => buy.OrderPrice).OrderBy(b => b.Key).Reverse();

                    // Create a temporary copy of the sell orders list so that we can group them by price
                    List <Model_SellOrder> tempGroupedSells = new List <Model_SellOrder>(comp.sellOrdersList);

                    /* Use an IEnumerable type object with a template of IGrouping to create a list of groups, grouped once again by the order price (becomes the Key). This
                     * also uses order by method to order the groups by their key. */
                    IEnumerable <IGrouping <Double, Model_SellOrder> > sells = tempGroupedSells.GroupBy(sell => sell.OrderPrice).OrderBy(a => a.Key);

                    int count = 0;  // counts which row we are adding to in the observer

                    // Iterate through all the groups in the orders list
                    foreach (IGrouping <Double, Model_BuyOrder> group in orders)
                    {
                        //this.dataGridView1.Rows.Add(1);
                        if (count == 10)
                        {
                            break;                                                     // only show the top 10
                        }
                        this.dataGridView1.Rows[count].Cells[0].Value = group.Count(); // Count() returns the number of elements that make up the group
                        this.dataGridView1.Rows[count].Cells[1].Value = group.Key;     // Key is the value that the group is grouped by (in this case, the order price)

                        Double totalVolume = 0.0;                                      // set a variable to keep track of the total volume in the group

                        // Iterate through each element of the grouping, adding up each element's volume to get the total volume of the group
                        foreach (Model_BuyOrder buy in group)
                        {
                            totalVolume += buy.OrderSize;
                        }
                        this.dataGridView1.Rows[count].Cells[2].Value = totalVolume; // write the total volume to the observer

                        count++;                                                     // go to the next row
                    }

                    int count2 = 0;     // another variable to count which row we are adding to in the observer

                    // Again, iterate throuh all the groups in the sells list
                    foreach (IGrouping <Double, Model_SellOrder> group in sells)
                    {
                        if (count2 == 10)
                        {
                            break;                                                      // only show the top 10
                        }
                        this.dataGridView1.Rows[count2].Cells[3].Value = group.Count(); // Count() returns the number of elements that make up the group
                        this.dataGridView1.Rows[count2].Cells[4].Value = group.Key;     // Key is the value that the group is grouped by (in this case, the order price)

                        Double totalVolume = 0.0;                                       // set a variable to keep track of the total volume in the group

                        // Iterate through each element of the grouping, adding up each element's volume to get the total volume of the group
                        foreach (Model_SellOrder sell in group)
                        {
                            totalVolume += sell.OrderSize;
                        }
                        this.dataGridView1.Rows[count2].Cells[5].Value = totalVolume;   // write the total volume to the observer

                        count2++;
                    }
                }
            }

            /* End the update method with an observer that shows the top bid prices grouped by bid price with the total volume of each group and the
             * number of elements that make up that group. The same information will the shown for sell prices */
        }
        public void Update(Model_RealTimeData subject)
        {
            // this update must reset all the values in the Stocks Stats Summary view!!

            /*Values to be printed include:
             *          - company name (always same)
             *          - company symbol (always same)
             *          - open price (i believe will always be the same)
             *          - last sale price
             *          - net change
             *          - image (either up arrow, down arrow or even arrow)
             *          - percent change
             *          - volume of shares */


            // first thing we should do is clear all the rows so that we can reprint the new data
            this.dataGridView1.Rows.Clear();

            Bitmap up       = new Bitmap(@"C:\Users\Adam\Documents\Visual Studio 2013\Projects\SE3352Assignment2\SE3352Assignment2\Resources\up.bmp", true);
            Bitmap down     = new Bitmap(@"C:\Users\Adam\Documents\Visual Studio 2013\Projects\SE3352Assignment2\SE3352Assignment2\Resources\down.bmp", true);
            Bitmap nochange = new Bitmap(@"C:\Users\Adam\Documents\Visual Studio 2013\Projects\SE3352Assignment2\SE3352Assignment2\Resources\noChange.bmp", true);

            // then iterate through all the companies and print their data
            foreach (Model_Company comp in subject.listOfCompanies)
            {
                // compute the net change
                Bitmap temp;
                // if the net change is currently 0 (this applies to the first time we update)
                if (comp.LastPrice > 0)
                {
                    comp.netChange = comp.LastPrice - comp.openPrice;
                }
                else
                {
                    comp.netChange = 0;
                }

                // determine which icon should be display
                if (comp.netChange > 0)
                {
                    // display the green up arrow
                    temp = new Bitmap(up);
                }

                else if (comp.netChange < 0)
                {
                    // display the red down arrow
                    temp = new Bitmap(down);
                }

                else
                {
                    // display the no change arrow
                    temp = new Bitmap(nochange);
                }

                comp.netChange     = Math.Round(comp.netChange, 2);
                comp.percentChange = Math.Round((comp.netChange / comp.openPrice * 100), 2);

                this.dataGridView1.Rows.Add(comp.companyName, comp.companyName, comp.openPrice, comp.LastPrice, comp.netChange,
                                            temp, comp.percentChange, comp.Volume);
            }
        }