public async Task <Account> BuyStock(Account buyer, string stock, int shares) { double stockPrice = await _stockPriceService.GetPrice(stock); double transactionAmount = stockPrice * shares; if (transactionAmount > buyer.Balance) { throw new InsufficientFundException(buyer.Balance, transactionAmount); } AssetTransaction assetTransaction = new AssetTransaction() { Account = buyer, Asset = new Asset { PricePerShare = stockPrice, Symbol = stock }, DateProcessed = DateTime.Now, IsPurchase = true, Shares = shares }; buyer.AssetTransactions.Add(assetTransaction); buyer.Balance -= transactionAmount; await _accountService.Update(buyer.Id, buyer); return(buyer); }
public async Task <Account> SellStock(Account seller, string symbol, int shares) { // Validate seller has sufficient shares. int accountShares = GetAccountSharesForSymbol(seller, symbol); if (accountShares < shares) { throw new InsufficientSharesException(symbol, accountShares, shares); } double stockPrice = await _stockPriceService.GetPrice(symbol); seller.AssetTransactions.Add(new AssetTransaction() { Account = seller, Asset = new Asset() { PricePerShare = stockPrice, Symbol = symbol }, DateProcessed = DateTime.Now, IsPurchase = false, Shares = shares }); seller.Balance += stockPrice * shares; await _accountService.Update(seller.Id, seller); return(seller); }
public async Task <Account> BuyStock(Account buyer, string symbol, int shares) { double stockPrice = await stockPriceService.GetPrice(symbol); double transactionPrice = stockPrice * shares; if (transactionPrice > buyer.Balance) { throw new InsufficientFundsException(buyer.Balance, transactionPrice); } AssetTransaction transaction = new AssetTransaction { Account = buyer, Asset = new Asset { PricePerShare = stockPrice, Symbol = symbol }, DateProcessed = DateTime.Now, Shares = shares, IsPurchase = true }; buyer.AssetTransactions.Add(transaction); buyer.Balance -= transactionPrice; await dataService.Update(buyer.Id, buyer); return(buyer); }
public async Task <Account> StockPurchase(Account Buyer, string Symbol, int Qty) { double StockPrice = await _SPS.GetPrice(Symbol); double TranxCost = StockPrice * Qty; if ((TranxCost) > Buyer.Balance) { throw new InsufficientBalanceX(Buyer.Balance, TranxCost); } AssetTransaction Tranx = new AssetTransaction() { WhichAccount = Buyer, WhichStock = new Stock() { PricePerShare = StockPrice, Symbol = Symbol }, DateProcessed = DateTime.Now, Shares = Qty, IsPurchase = true }; Buyer.AssetTransactions.Add(Tranx); Buyer.Balance -= TranxCost; await _AccS.Update(Buyer.Id, Buyer); return(Buyer); }
public async void Execute(object parameter) { try { double stockPrice = await _stockPriceService.GetPrice(_buyViewModel.Symbol); _buyViewModel.StockPrice = stockPrice; } catch (Exception e) { MessageBox.Show($"{e.Message}............{e.ToString()}"); } }
public async void Execute(object parameter) { try { double stockPrice = await _stockPriceService.GetPrice(_buyViewModel.Symbol); _buyViewModel.SearchResultSymbol = _buyViewModel.Symbol.ToUpper(); _buyViewModel.StockPrice = stockPrice; } catch (Exception e) { MessageBox.Show(e.Message); } }
public async void Execute(object parameter) { try { double SPr = await _SPS.GetPrice(_BVM.Symbol); _BVM.SrchResSymb = _BVM.Symbol.ToUpper(); _BVM.StkPr = SPr; } catch (Exception f) { MessageBox.Show(f.Message); } }
public async void Execute(object parameter) { try { var stockPrice = await _stockPriceService.GetPrice(_buyViewModel.Symbol).ConfigureAwait(false); _buyViewModel.SearchResultSymbol = _buyViewModel.Symbol.ToUpperInvariant(); _buyViewModel.StockPrice = stockPrice; } catch (Exception e) { MessageBox.Show(e.Message); } }
public override async Task ExecuteAsync(object parameter) { try { double stockPrice = await stockPriceService.GetPrice(viewModel.Symbol); viewModel.StockPrice = stockPrice; viewModel.SearchResultSymbol = viewModel.Symbol.ToUpper(); } catch (InvalidCastException) { viewModel.ErrorMessage = "Symbol does not Exist"; } catch (Exception) { viewModel.ErrorMessage = "Failed to get symbol information."; } }
public override async Task ExecuteAsync(object parameter) { try { double stockPrice = await _stockPriceService.GetPrice(_viewModel.Symbol); _viewModel.SearchResultSymbol = _viewModel.Symbol.ToUpper(); _viewModel.StockPrice = stockPrice; _viewModel.ErrorMessage = string.Empty; } catch (InvalidSymbolException) { _viewModel.ErrorMessage = "Symbol does not exist."; } catch (Exception) { _viewModel.ErrorMessage = "Failed to get symbol information."; } }