Exemplo n.º 1
0
        public void Sell(BoardSecurity sellingSecurity)
        {
            // TODO: check if we have this security at all
            var sellQuantity = OwnedSecurities.First(x => x.Security == sellingSecurity.Security).Quantity;

            Sell(sellingSecurity, sellQuantity);
        }
Exemplo n.º 2
0
        public int MaxBuy(BoardSecurity purchaseSecurity)
        {
            int affordableShares = ((Balance / (purchaseSecurity.CostPerShare) / 10) * 10); // TODO: technically this should be only in groups of 10

            Buy(purchaseSecurity, affordableShares);
            return(affordableShares);
        }
Exemplo n.º 3
0
        public void Sell(BoardSecurity sellingSecurity, int sellQuantity)
        {
            // TODO: check if we have this security at all
            if (OwnedSecurities.First(x => x.Security == sellingSecurity.Security).Quantity < sellQuantity)
            {
                // Not enough of this sellingSecurities to do this transaction
                return;
            }
            // TODO: adjust sellQuantity available in gameplay
            OwnedSecurities.First(x => x.Security == sellingSecurity.Security).Quantity -= sellQuantity;
            Balance += sellingSecurity.CostPerShare * sellQuantity;

            if (sellQuantity > 0)
            {
                System.Console.WriteLine($"{Name} sold {sellQuantity} shares of {sellingSecurity.Security.Name} for {sellingSecurity.CostPerShare * sellQuantity}");
            }
        }
Exemplo n.º 4
0
        public void Buy(BoardSecurity purchaseSecurity, int purchaseQuantity)
        {
            var cost = purchaseSecurity.CostPerShare * purchaseQuantity;

            if (cost > Balance)
            {
                // Not enough $ to do this transaction
                return;
            }
            // TODO: adjust sellQuantity available in gameplay
            if (OwnedSecurities.First(s => s.Security == purchaseSecurity.Security) == null)
            {
                OwnedSecurities.Add(new PurchasedSecurity(purchaseSecurity.Security));
            }

            OwnedSecurities.First(s => s.Security == purchaseSecurity.Security).Quantity += purchaseQuantity;
            Balance -= cost;

            if (purchaseQuantity > 0)
            {
                System.Console.WriteLine($"{Name} purchased {purchaseQuantity} shares of {purchaseSecurity.Security.Name} for {cost}");
            }
        }