/// <summary>
        /// Constructor for BuyOrSell object
        /// </summary>
        /// <param name="stock">Stock object that is being bought or sold</param>
        /// <param name="quanittyIn">Number of shares bought</param>
        /// <param name="BORSIn">Whether the stock was bought or sold</param>
        public BuyOrSell_M(Stock_M stock, int quanittyIn, BuyOrSellEnum BORSIn)
        {
            StockName     = stock.Name;
            PricePerStock = stock.Price;

            Quantity = quanittyIn;

            BuyOrSellState = BORSIn;
        }
Esempio n. 2
0
        /// <summary>
        /// Checks to see if two stock objects are equal
        /// </summary>
        /// <param name="obj">Stock object to be checked</param>
        /// <returns>Boolean value of whether or not two stock objects are equal</returns>
        public override bool Equals(Object obj)
        {
            Stock_M stock = obj as Stock_M;

            if (stock == null)
            {
                return(false);
            }
            return(Name == stock.Name && Tag == stock.Tag && _price == stock.Price);
        }
Esempio n. 3
0
        /// <summary>
        /// Deletes a portfolio from the account
        /// </summary>
        /// <param name="name">Name of portfolio to be deleted</param>
        public void DeletePortfolio(string name, List <Stock_M> stocks)
        {
            Portfolio_M selectedPortfolio = GetPortfolioByName(name);

            foreach (BuyOrSell_M BOS in selectedPortfolio.CurrentlyHeld())
            {
                Stock_M stock = stocks.Find(s => BOS.StockName == s.Name);
                selectedPortfolio.SellStock(stock, BOS.Quantity);
            }

            _transactions.AddRange(selectedPortfolio.TransactionList);
            if (_portfolios.RemoveAll((p) => p.Name == name) == 0)
            {
                throw new ArgumentException("No portfolio exists with that name.");
            }
        }
        private Error SellStocks(StockEvent e)
        {
            Stock_M s = _mainModel.Stocks.Find((stock) => stock.Tag == e.Name);

            if (s != null)
            {
                BuyOrSell_M bos = _currentPortfolio.CurrentlyHeld().Find(b => b.StockName == s.Name);
                if (e.Amount > bos.Quantity)
                {
                    return(new Error("Selling too many stocks"));
                }
                _currentPortfolio.SellStock(s, e.Amount);
            }
            Broadcast(new PortfolioEvent("portfolio", _currentPortfolio.Name));
            return(Error.None);
        }
Esempio n. 5
0
 /// <summary>
 /// Sells the amount given of a stock held in the portfolio and sends the cash back to the account funds
 /// </summary>
 /// <param name="stock"></param>
 /// <param name="amount"></param>
 public void SellStock(Stock_M stock, int amount)
 {
     if (_verifierStock(stock))
     {
         if (_fundsManager(BuyOrSell_M.BuyOrSellEnum.Sell, (stock.Price * amount), Fee_M.BUY_OR_SELL))
         {
             BuyOrSell_M buyOrSell = new BuyOrSell_M(stock, amount, BuyOrSell_M.BuyOrSellEnum.Sell);
             _transactionList.Add(buyOrSell);
             Fee_M fee = new Fee_M(Fee_M.FeeSelect.BuyOrSell);
             _transactionList.Add(fee);
         }
         else
         {
             throw new ArgumentException("Not enough cash");
         }
     }
 }
        /// <summary>
        /// Gets the name, tag, and price for all the companies in the text file and puts them into stocks
        /// </summary>
        public void LoadTickersFromFile()
        {
            string[] lines = System.IO.File.ReadAllLines("Ticker.txt");
            foreach (string line in lines)
            {
                if (line != "")
                {
                    string[] parts = line.Split('-');

                    string name  = parts[1];
                    string tag   = parts[0];
                    double price = Convert.ToDouble(parts[2].Substring(1));

                    Stock_M stock = new Stock_M(name, tag, price);
                    _stocks.Add(stock);
                }
            }
        }
        private Error BuyStocks(StockEvent e)
        {
            Stock_M s = _mainModel.Stocks.Find((stock) => stock.Tag == e.Name);

            if (s != null)
            {
                if (_currentPortfolio.CurrentlyHeld().Exists(b => b.StockName == s.Name))
                {
                    return(new Error("Cannot buy stock you already own"));
                }
                try
                {
                    _currentPortfolio.PurchaseStock(s, e.Amount);
                }
                catch (ArgumentException err)
                {
                    return(new Error(err.Message));
                }
            }
            Broadcast(new PortfolioEvent("portfolio", _currentPortfolio.Name));
            return(Error.None);
        }
 /// <summary>
 /// Returns whether the stock is contained in the list of stocks
 /// </summary>
 /// <param name="stock"></param>
 /// <returns></returns>
 public bool VerifyStock(Stock_M stock)
 {
     return(_stocks.Contains(stock));
     //return stocks.Find((s) => s.Equals(stock)) != null;
 }