Example #1
0
        public BuyViewModel(IStockPriceService stockPriceService, IBuyStockService buyStockService, IAccountStore accountStore)
        {
            SearchSymbolCommand = new SearchSymbolCommand(this, stockPriceService);
            BuyStockCommand     = new BuyStockCommand(this, buyStockService, accountStore);

            ErrorMessageViewModel  = new MessageViewModel();
            StatusMessageViewModel = new MessageViewModel();
        }
Example #2
0
        public static void Execute()
        {
            ConsoleExtension.WriteSeparator("Stock example");

            var stock = new Stock("Tesla", 5);

            var buyStock  = new BuyStockCommand(stock);
            var sellStock = new SellStockCommand(stock);

            var broker = new Broker();

            broker.TakeOrder(buyStock);
            broker.TakeOrder(sellStock);

            broker.ProcessOrders();
        }
Example #3
0
        public CommandStatus Handle(BuyStockCommand command)
        {
            var portfolio = _repo.Load();

            var newStock = new Portfolio.Stock {
                Name         = command.StockName,
                Symbol       = command.StockSymbol,
                Currency     = command.StockPriceCurrency,
                Qty          = command.Qty,
                BuyingPrice  = command.StockPrice,
                Bought       = command.Bought,
                CurrentPrice = command.StockPrice,
                LastUpdated  = DateTime.Now
            };

            portfolio.Entries.Add(newStock);

            _repo.Store(portfolio);
            return(new Success());
        }
        public bool SelectStockToBuy(CandidateStocksQueryResult candidates, out BuyStockCommand command)
        {
            BuyStockCommand buyCmd = null;

            DisplayBuyCandidates(candidates.Candidates);
            Let_user_select_by_index("Enter index of stock to buy: ", index => {
                var chosenStock = candidates.Candidates[index];
                DisplayChosenCandidate(chosenStock);
                Ask_user_for_qty_to_buy(qty => {
                    buyCmd = new BuyStockCommand {
                        StockName          = chosenStock.Name,
                        StockSymbol        = chosenStock.Symbol,
                        StockPriceCurrency = chosenStock.Currency,
                        Qty        = qty,
                        StockPrice = chosenStock.Price,
                        Bought     = DateTime.Now
                    };
                });
            });

            command = buyCmd;
            return(command != null);


            void Ask_user_for_qty_to_buy(Action <int> onQty)
            {
                Console.Write("Buy qty?: ");
                var input = Console.ReadLine();

                if (input == "")
                {
                    return;
                }

                var qty = int.Parse(input);

                onQty(qty);
            }
        }
Example #5
0
 public BuyViewModel(IStockPriceService stockPriceService, IBuyStockService buyStockService)
 {
     SearchSymbolCommand = new SearchSymbolCommand(this, stockPriceService);
     BuyStockCommand     = new BuyStockCommand(this, buyStockService);
 }
 public CommandStatus Handle(BuyStockCommand command)
 => _client.Execute <HttpCommandStatus>("buystockcommand", command).CommandStatus;
Example #7
0
 public HttpCommandStatus Handle([Payload] BuyStockCommand command)
 => new HttpCommandStatus(Handler.Handle(command));