Exemplo n.º 1
0
        public Trade(InvestmentAccount account, Asset asset, char action)
        {
            Action = action;  //buy or sell
            Asset  = asset;


            if (action == 'b')  // b for buy
            {
                try
                {
                    asset.WithdrawAsset(account);       //Withdraw funds to cover the buy
                    account.AddInvestmentAssets(asset); //Asset bought. Add to account.
                }
                catch (InsufficientFundsException)
                {
                    throw;
                }
            }
            else  //we are selling
            {
                try
                {
                    Validator.VerifyAssets(account, asset); //are we trying to sell what we don't have?

                    RemoveTradeAsset(account, asset);

                    asset.DepositAsset(account); //but adds funds gained from sale
                }
                catch (InvalidTradeException)
                {
                    throw;
                }
            }
        }