use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class Repayments method accept.
@Override
public void accept(final Portfolio portfolio, final Authenticated authenticated) {
final PortfolioOverview portfolioOverview = portfolio.calculateOverview();
final Collection<Integer> active = getActiveLastTime();
// detect and process loans that have been fully repaid, comparing to the last time active loans were checked
final Stream<Investment> repaid = portfolio.getActiveWithPaymentStatus(PaymentStatuses.of(PaymentStatus.PAID));
repaid.filter(i -> active.contains(i.getLoanId())).peek(i -> {
final Loan l = authenticated.call(zonky -> LoanCache.INSTANCE.getLoan(i, zonky));
final Event e = new LoanRepaidEvent(i, l, portfolioOverview);
Events.fire(e);
}).forEach(i -> active.remove(i.getLoanId()));
// add all active loans to date
portfolio.getActiveWithPaymentStatus(PaymentStatus.getActive()).forEach(i -> active.add(i.getLoanId()));
// store for future reference
setActive(active);
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class Purchasing method execute.
@Override
protected Collection<Investment> execute(final Portfolio portfolio, final PurchaseStrategy strategy, final Collection<Participation> marketplace) {
final Stream<ParticipationDescriptor> participations = marketplace.parallelStream().map(p -> toDescriptor(p, auth)).filter(d -> {
// never re-purchase what was once sold
final Loan l = d.related();
final boolean wasSoldBefore = portfolio.wasOnceSold(l);
if (wasSoldBefore) {
LOGGER.debug("Ignoring loan #{} as the user had already sold it before.", l.getId());
}
return !wasSoldBefore;
});
final RestrictedPurchaseStrategy s = new RestrictedPurchaseStrategy(strategy, auth.getRestrictions());
return Session.purchase(portfolio, auth, participations, s, dryRun);
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class Session method purchase.
public boolean purchase(final RecommendedParticipation recommendation) {
Events.fire(new PurchaseRequestedEvent(recommendation));
final Participation participation = recommendation.descriptor().item();
final Loan loan = recommendation.descriptor().related();
final boolean purchased = isDryRun || actualPurchase(participation);
if (purchased) {
final Investment i = Investment.fresh(participation, loan, recommendation.amount());
markSuccessfulPurchase(i);
Events.fire(new InvestmentPurchasedEvent(i, loan, portfolioOverview));
}
return purchased;
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class Session method purchase.
public static Collection<Investment> purchase(final Portfolio portfolio, final Authenticated auth, final Stream<ParticipationDescriptor> items, final RestrictedPurchaseStrategy strategy, final boolean dryRun) {
final Session session = new Session(portfolio, items, auth, dryRun);
final Collection<ParticipationDescriptor> c = session.getAvailable();
if (c.isEmpty()) {
return Collections.emptyList();
}
Events.fire(new PurchasingStartedEvent(c, session.portfolioOverview));
session.purchase(strategy);
final Collection<Investment> result = session.getResult();
Events.fire(new PurchasingCompletedEvent(result, session.portfolioOverview));
return Collections.unmodifiableCollection(result);
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class Session method invest.
public static Collection<Investment> invest(final Portfolio portfolio, final Investor investor, final Authenticated auth, final Collection<LoanDescriptor> loans, final RestrictedInvestmentStrategy strategy) {
final Session session = new Session(portfolio, loans, investor, auth);
final PortfolioOverview portfolioOverview = session.portfolioOverview;
final int balance = portfolioOverview.getCzkAvailable();
Events.fire(new ExecutionStartedEvent(loans, portfolioOverview));
if (balance >= Defaults.MINIMUM_INVESTMENT_IN_CZK && !session.getAvailable().isEmpty()) {
session.invest(strategy);
}
final Collection<Investment> result = session.getResult();
// make sure we get fresh portfolio reference here
Events.fire(new ExecutionCompletedEvent(result, session.portfolioOverview));
return Collections.unmodifiableCollection(result);
}
Aggregations