use of com.github.robozonky.app.investing.Investing in project robozonky by RoboZonky.
the class InvestingDaemon method execute.
@Override
protected void execute(final Portfolio portfolio, final Authenticated authenticated) {
// don't query anything unless we have enough money to invest
final int balance = portfolio.getRemoteBalance().get().intValue();
final int minimum = Defaults.MINIMUM_INVESTMENT_IN_CZK;
if (balance < minimum) {
LOGGER.debug("Asleep as there is not enough available balance. ({} < {})", balance, minimum);
return;
}
// query marketplace for investment opportunities
final Collection<LoanDescriptor> loans = authenticated.call(zonky -> zonky.getAvailableLoans(SELECT)).parallel().filter(// re-investing would fail
l -> !l.getMyInvestment().isPresent()).map(l -> {
/*
* Loan is first retrieved from the authenticated API. This way, we get all available
* information, such as borrower nicknames from other loans made by the same person.
*/
final Loan complete = authenticated.call(zonky -> LoanCache.INSTANCE.getLoan(l.getId(), zonky));
/*
* We update the loan within the cache with latest information from the marketplace. This is
* done so that we don't cache stale loan information, such as how much of the loan is remaining
* to be invested.
*/
Loan.updateFromMarketplace(complete, l);
return complete;
}).map(LoanDescriptor::new).collect(Collectors.toList());
investing.apply(portfolio, loans);
}
Aggregations