コード例 #1
0
        /// <summary>
        /// Buys a specified amount of stock of a specified stock
        /// </summary>
        /// <param name="tickerName">The abbreviation of the stock to buy</param>
        /// <param name="amt">The amount to buy</param>
        /// <returns>Error if trying to buy less than 1 share, Error if stock doesnt exist, Error if insufficient funds, Error if already own stocks in company. </returns>
        private Error PortBuy(string tickerName, int amt)
        {
            if (amt <= 0)
            {
                return(new Error("Cannot buy less than 1 share"));
            }
            Ticker t = GetTickerByAbbr(tickerName.ToUpper());

            if (t == null)
            {
                return(new Error("A stock with that abbreviation does not exist."));
            }

            double totalCost = (t.Price * amt) + TRADE_FEE;

            if (totalCost > _acct.Funds)
            {
                return(new Error("You have inssuficient funds for this transaction."));
            }
            else
            {
                if (_currentPortfolio.Stocks.Exists(pur => pur.Ticker.Tag == tickerName))
                {
                    return(new Class_Library.Error("You cannot buy stock from a company you already have stock in: "));
                }
                _currentPortfolio.AmountStocks += amt;
                StockPurchase stock = new StockPurchase(t, amt);
                _currentPortfolio.Stocks.Add(stock);
                _acct.Funds -= totalCost;
                _currentPortfolio.TotalFees += TRADE_FEE;
                return(Error.None);
            }
        }
コード例 #2
0
 /// <summary>
 /// Add
 /// Returns the new stock with the amount of stocks purchased added together
 /// </summary>
 /// <param name="price"></param>
 /// <returns></returns>
 public StockPurchase Add(StockPurchase SP)
 {
     return(new StockPurchase(_ticker, _amount + SP._amount));
 }
コード例 #3
0
 /// <summary>
 /// HasSameTicker
 /// returns whether the StockPurchase passed has the same ticker as the instance
 /// </summary>
 /// <param name="price"></param>
 /// <returns></returns>
 public bool HasSameTicker(StockPurchase SP)
 {
     return(SP.Ticker.Equals(_ticker));
 }