Пример #1
0
 /// <summary>
 /// Sell commodoty method
 /// Checks:
 /// if trade is profatble
 /// credits the profit back in wallet
 /// </summary>
 /// <param name="sellingCommodity"></param>
 public void Sell(ICommodity sellingCommodity)
 {
     if (!TxProfitValidator.IsValid())
     {
         throw new Exception("The trade is not profitable");
     }
     using (var myWallet = new GoldWallet(WalletService.FetchBalance(), new GoldTaxLoad()))
     {
         using (var ts = new TransactionScope())
         {
             TxCommodity.Quantity -= TxTrade.TradeQuantity;
             myWallet.Credit(TxTrade.GetTradeCost() - (GoldTaxLoad.GoldBuyTransactionCharges * sellingCommodity.Quantity));
         }
     }
 }
Пример #2
0
 /// <summary>
 /// Buy commodity
 /// Checks:
 /// if wallet has balance
 /// add tx in ledger
 /// </summary>
 public void Buy()
 {
     if (!TxTradeValidator.IsValid())
     {
         return;
     }
     using (var myWallet = new GoldWallet(WalletService.FetchBalance(), new GoldTaxLoad()))
     {
         using (var ts = new TransactionScope())
         {
             myWallet.Debit(TxTrade.GetTradeCost());
             WalletService.WalletBalance = myWallet.GetBalance();
             TxCommodity = new GoldCommodity(TxTrade.TradePrice, TxCommodity.Quantity + TxTrade.TradeQuantity);
             TransactionLedgerService.MasterLedger.HistoryTransactions.Add(TxCommodity);
         }
     }
 }