Search in sources :

Example 1 with SaleRecommendedEvent

use of com.github.robozonky.api.notifications.SaleRecommendedEvent in project robozonky by RoboZonky.

the class Selling method sell.

private void sell(final Portfolio portfolio, final SellStrategy strategy, final Authenticated auth) {
    final PortfolioOverview overview = portfolio.calculateOverview();
    final Set<InvestmentDescriptor> eligible = portfolio.getActiveForSecondaryMarketplace().parallel().map(i -> getDescriptor(i, auth)).collect(Collectors.toSet());
    Events.fire(new SellingStartedEvent(eligible, overview));
    final Collection<Investment> investmentsSold = strategy.recommend(eligible, overview).peek(r -> Events.fire(new SaleRecommendedEvent(r))).map(r -> auth.call(zonky -> processInvestment(zonky, r))).flatMap(o -> o.map(Stream::of).orElse(Stream.empty())).collect(Collectors.toSet());
    Events.fire(new SellingCompletedEvent(investmentsSold, portfolio.calculateOverview()));
}
Also used : SaleRecommendedEvent(com.github.robozonky.api.notifications.SaleRecommendedEvent) Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Zonky(com.github.robozonky.common.remote.Zonky) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) SaleRequestedEvent(com.github.robozonky.api.notifications.SaleRequestedEvent) InvestmentDescriptor(com.github.robozonky.api.strategies.InvestmentDescriptor) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) RecommendedInvestment(com.github.robozonky.api.strategies.RecommendedInvestment) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) Stream(java.util.stream.Stream) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) LoanCache(com.github.robozonky.app.util.LoanCache) Events(com.github.robozonky.app.Events) Authenticated(com.github.robozonky.app.authentication.Authenticated) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Optional(java.util.Optional) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) SellStrategy(com.github.robozonky.api.strategies.SellStrategy) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) SaleRecommendedEvent(com.github.robozonky.api.notifications.SaleRecommendedEvent) InvestmentDescriptor(com.github.robozonky.api.strategies.InvestmentDescriptor) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) RecommendedInvestment(com.github.robozonky.api.strategies.RecommendedInvestment) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment)

Aggregations

SaleOfferedEvent (com.github.robozonky.api.notifications.SaleOfferedEvent)1 SaleRecommendedEvent (com.github.robozonky.api.notifications.SaleRecommendedEvent)1 SaleRequestedEvent (com.github.robozonky.api.notifications.SaleRequestedEvent)1 SellingCompletedEvent (com.github.robozonky.api.notifications.SellingCompletedEvent)1 SellingStartedEvent (com.github.robozonky.api.notifications.SellingStartedEvent)1 RawInvestment (com.github.robozonky.api.remote.entities.RawInvestment)1 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)1 InvestmentDescriptor (com.github.robozonky.api.strategies.InvestmentDescriptor)1 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)1 RecommendedInvestment (com.github.robozonky.api.strategies.RecommendedInvestment)1 SellStrategy (com.github.robozonky.api.strategies.SellStrategy)1 Events (com.github.robozonky.app.Events)1 Authenticated (com.github.robozonky.app.authentication.Authenticated)1 LoanCache (com.github.robozonky.app.util.LoanCache)1 Zonky (com.github.robozonky.common.remote.Zonky)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1