Exemple #1
0
        /// <summary>
        /// Executes a buy stock transaction
        /// </summary>
        /// <param name="stvm"></param>
        public void BuyStock(StockTransactionViewModel stvm)
        {
            //charge current stock trading account
            _accounts[0].Balance -= stvm.CurrentPricePerShare * stvm.Quantity;

            //add a new position
            _stockPositions.Add(new StockPositionViewModel
            {
                PricePaid          = stvm.CurrentPricePerShare,
                Quantity           = stvm.Quantity,
                StockTickerDetails = _stockDetailsDictionary[stvm.Symbol]
            });
            //insert a transaction into history
            _stockTransactionHistory.Add(stvm);
        }
Exemple #2
0
        /// <summary>
        /// Executes a sell stock transaction
        /// </summary>
        /// <param name="stvm"></param>
        public void SellStock(StockTransactionViewModel stvm)
        {
            //charge current stock trading account
            _accounts[0].Balance += stvm.CurrentPricePerShare * stvm.Quantity;

            //set the final price the transaction was executed for
            stvm.PricePerShare = stvm.CurrentPricePerShare;
            //remove a new position
            StockPositionViewModel stockToSell = _stockPositions.First(x => x.ID == stvm.StockPosition.ID);

            if (stockToSell.Quantity == stvm.Quantity)
            {
                _stockPositions.Remove(stockToSell);
            }
            else
            {
                stockToSell.Quantity -= stvm.Quantity;
            }
            //insert a transaction into history
            _stockTransactionHistory.Add(stvm);
        }