Search in sources :

Example 1 with Select

use of com.github.robozonky.common.remote.Select 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);
}
Also used : InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Collection(java.util.Collection) Investing(com.github.robozonky.app.investing.Investing) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) Select(com.github.robozonky.common.remote.Select) Consumer(java.util.function.Consumer) Investor(com.github.robozonky.app.investing.Investor) LoanCache(com.github.robozonky.app.util.LoanCache) Authenticated(com.github.robozonky.app.authentication.Authenticated) Duration(java.time.Duration) Optional(java.util.Optional) Defaults(com.github.robozonky.internal.api.Defaults) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor)

Example 2 with Select

use of com.github.robozonky.common.remote.Select in project robozonky by RoboZonky.

the class PurchasingDaemon method execute.

@Override
protected void execute(final Portfolio portfolio, final Authenticated authenticated) {
    final long balance = portfolio.getRemoteBalance().get().longValue();
    final Select s = new Select().lessThanOrEquals("remainingPrincipal", balance);
    final Collection<Participation> p = authenticated.call(zonky -> zonky.getAvailableParticipations(s).collect(Collectors.toList()));
    purchasing.apply(portfolio, p);
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) Select(com.github.robozonky.common.remote.Select)

Aggregations

Select (com.github.robozonky.common.remote.Select)2 Participation (com.github.robozonky.api.remote.entities.Participation)1 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)1 InvestmentStrategy (com.github.robozonky.api.strategies.InvestmentStrategy)1 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)1 Authenticated (com.github.robozonky.app.authentication.Authenticated)1 Investing (com.github.robozonky.app.investing.Investing)1 Investor (com.github.robozonky.app.investing.Investor)1 Portfolio (com.github.robozonky.app.portfolio.Portfolio)1 LoanCache (com.github.robozonky.app.util.LoanCache)1 Defaults (com.github.robozonky.internal.api.Defaults)1 Duration (java.time.Duration)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1