Search in sources :

Example 1 with SellingCompletedEvent

use of com.github.robozonky.api.notifications.SellingCompletedEvent 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)

Example 2 with SellingCompletedEvent

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

the class JmxListenerService method newListener.

private static <T extends Event> EventListener<T> newListener(final Class<T> eventType) {
    if (Objects.equals(eventType, ExecutionStartedEvent.class)) {
        return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((ExecutionStartedEvent) event));
    } else if (Objects.equals(eventType, ExecutionCompletedEvent.class)) {
        return (event, sessionInfo) -> {
            final ExecutionCompletedEvent evt = (ExecutionCompletedEvent) event;
            callOnRuntime(bean -> bean.handle(evt, sessionInfo));
            callOnPortfolio(bean -> bean.handle(evt));
        };
    } else if (Objects.equals(eventType, SellingStartedEvent.class)) {
        return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((SellingStartedEvent) event));
    } else if (Objects.equals(eventType, SellingCompletedEvent.class)) {
        return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((SellingCompletedEvent) event));
    } else if (Objects.equals(eventType, PurchasingStartedEvent.class)) {
        return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((PurchasingStartedEvent) event));
    } else if (Objects.equals(eventType, PurchasingCompletedEvent.class)) {
        return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((PurchasingCompletedEvent) event));
    } else if (Objects.equals(eventType, InvestmentDelegatedEvent.class)) {
        return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentDelegatedEvent) event));
    } else if (Objects.equals(eventType, InvestmentRejectedEvent.class)) {
        return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentRejectedEvent) event));
    } else if (Objects.equals(eventType, InvestmentMadeEvent.class)) {
        return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentMadeEvent) event));
    } else if (Objects.equals(eventType, SaleOfferedEvent.class)) {
        return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((SaleOfferedEvent) event));
    } else if (Objects.equals(eventType, InvestmentPurchasedEvent.class)) {
        return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentPurchasedEvent) event));
    } else {
        return null;
    }
}
Also used : EventListenerSupplier(com.github.robozonky.api.notifications.EventListenerSupplier) ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) Logger(org.slf4j.Logger) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) LoggerFactory(org.slf4j.LoggerFactory) ExecutionStartedEvent(com.github.robozonky.api.notifications.ExecutionStartedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) ListenerService(com.github.robozonky.api.notifications.ListenerService) Event(com.github.robozonky.api.notifications.Event) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) Objects(java.util.Objects) Consumer(java.util.function.Consumer) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) Map(java.util.Map) EventListener(com.github.robozonky.api.notifications.EventListener) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) Optional(java.util.Optional) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) Collections(java.util.Collections) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) ExecutionStartedEvent(com.github.robozonky.api.notifications.ExecutionStartedEvent) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent)

Aggregations

SaleOfferedEvent (com.github.robozonky.api.notifications.SaleOfferedEvent)2 SellingCompletedEvent (com.github.robozonky.api.notifications.SellingCompletedEvent)2 SellingStartedEvent (com.github.robozonky.api.notifications.SellingStartedEvent)2 Optional (java.util.Optional)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Event (com.github.robozonky.api.notifications.Event)1 EventListener (com.github.robozonky.api.notifications.EventListener)1 EventListenerSupplier (com.github.robozonky.api.notifications.EventListenerSupplier)1 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)1 ExecutionStartedEvent (com.github.robozonky.api.notifications.ExecutionStartedEvent)1 InvestmentDelegatedEvent (com.github.robozonky.api.notifications.InvestmentDelegatedEvent)1 InvestmentMadeEvent (com.github.robozonky.api.notifications.InvestmentMadeEvent)1 InvestmentPurchasedEvent (com.github.robozonky.api.notifications.InvestmentPurchasedEvent)1 InvestmentRejectedEvent (com.github.robozonky.api.notifications.InvestmentRejectedEvent)1 ListenerService (com.github.robozonky.api.notifications.ListenerService)1 PurchasingCompletedEvent (com.github.robozonky.api.notifications.PurchasingCompletedEvent)1 PurchasingStartedEvent (com.github.robozonky.api.notifications.PurchasingStartedEvent)1 SaleRecommendedEvent (com.github.robozonky.api.notifications.SaleRecommendedEvent)1 SaleRequestedEvent (com.github.robozonky.api.notifications.SaleRequestedEvent)1