Class StockService
java.lang.Object
com.truebubo.maniflow.stock.StockService
Handles business logic behind stocks
-
Constructor Summary
ConstructorsConstructorDescriptionStockService
(StockRepository stockRepository, StockPriceFinder stockPriceFinder, IncomeRepository incomeRepository, ExpenseRepository expenseRepository) Initializes stock service with repositories -
Method Summary
-
Constructor Details
-
StockService
public StockService(@NonNull StockRepository stockRepository, @NonNull StockPriceFinder stockPriceFinder, @NonNull IncomeRepository incomeRepository, @NonNull ExpenseRepository expenseRepository) Initializes stock service with repositories- Parameters:
stockRepository
- Stock repositorystockPriceFinder
- Finds stock pricesincomeRepository
- Income repositoryexpenseRepository
- Expense repository
-
-
Method Details
-
getStockHoldings
-
buyStock
public void buyStock(@NonNull Stock stock) throws StockNotFoundException, NotEnoughMoneyToBuyException Buys the stocks. The price will be deducted as a one-time expense- Parameters:
stock
- Information about the stock bought- Throws:
StockNotFoundException
- Stock was not found by an APINotEnoughMoneyToBuyException
- The price of stocks to be bought is higher than money the user owns
-
sellStock
public void sellStock(@NonNull Stock stock) throws TooFewStocksOwnedException, StockNotFoundException Sells the stocks. The price will be accounted as a one-time income- Parameters:
stock
- Information about the stock sold- Throws:
TooFewStocksOwnedException
- When quantity sold is larger than ownedStockNotFoundException
- Stock was not found by an API
-