コード例 #1
0
        /// <summary>
        /// Update the portfolio on stock buy.
        /// </summary>
        /// <param name="stock"></param>
        /// <param name="count"></param>
        /// <param name="averageCost"></param>
        /// <returns>
        ///  0 -> success
        ///  others -> error
        /// </returns>
        public int UpdateOnBuy(Stock stock, int count, double averageCost)
        {
            if (!PortfolioStocks.ContainsKey(stock.Symbol))
            {
                PortfolioStocks[stock.Symbol] = new StockData(stock);
            }

            return(PortfolioStocks[stock.Symbol].UpdateOnBuy(count, averageCost));
        }
コード例 #2
0
        /// <summary>
        /// Update the portfolio on stock sale.
        /// </summary>
        /// <param name="stock"></param>
        /// <param name="count"></param>
        /// <param name="averagePrice"></param>
        /// <returns>
        ///  0 -> success
        /// -1 -> Protfolio does not contain the stock
        ///  other -> error
        /// </returns>
        public int UpdateOnSell(Stock stock, int count, double averagePrice)
        {
            var result = -1;

            if (PortfolioStocks.ContainsKey(stock.Symbol))
            {
                result = PortfolioStocks[stock.Symbol].UpdateOnBuy(count, averagePrice);
            }

            return(result);
        }