Search in sources :

Example 1 with SellStrategy

use of com.github.robozonky.api.strategies.SellStrategy in project robozonky by RoboZonky.

the class NaturalLanguageSellStrategyTest method noLoansApplicable.

@Test
void noLoansApplicable() {
    final MarketplaceFilter filter = MarketplaceFilter.of(MarketplaceFilterCondition.alwaysAccepting());
    final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.PROGRESSIVE, Collections.singleton(filter));
    final SellStrategy s = new NaturalLanguageSellStrategy(p);
    final PortfolioOverview portfolio = mock(PortfolioOverview.class);
    when(portfolio.getCzkAvailable()).thenReturn(p.getMinimumBalance());
    when(portfolio.getCzkInvested()).thenReturn(p.getMaximumInvestmentSizeInCzk() - 1);
    final Stream<RecommendedInvestment> result = s.recommend(Collections.singletonList(mockDescriptor()), portfolio);
    assertThat(result).isEmpty();
}
Also used : SellStrategy(com.github.robozonky.api.strategies.SellStrategy) MarketplaceFilter(com.github.robozonky.strategy.natural.conditions.MarketplaceFilter) RecommendedInvestment(com.github.robozonky.api.strategies.RecommendedInvestment) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Test(org.junit.jupiter.api.Test)

Example 2 with SellStrategy

use of com.github.robozonky.api.strategies.SellStrategy 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 3 with SellStrategy

use of com.github.robozonky.api.strategies.SellStrategy in project robozonky by RoboZonky.

the class StrategyLoaderTest method loading.

@Test
void loading() {
    final InvestmentStrategy is = (availableLoans, portfolio, restrictions) -> Stream.empty();
    final StrategyService iss = new StrategyService() {

        @Override
        public Optional<InvestmentStrategy> toInvest(final String strategy) {
            return Optional.of(is);
        }

        @Override
        public Optional<SellStrategy> toSell(final String strategy) {
            return Optional.empty();
        }

        @Override
        public Optional<PurchaseStrategy> toPurchase(final String strategy) {
            return Optional.empty();
        }
    };
    assertThat(StrategyLoader.load("", Collections.singleton(iss), StrategyService::toInvest)).contains(is);
}
Also used : Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) StrategyService(com.github.robozonky.api.strategies.StrategyService) Stream(java.util.stream.Stream) SoftAssertions(org.assertj.core.api.SoftAssertions) Optional(java.util.Optional) Assertions(org.assertj.core.api.Assertions) UUID(java.util.UUID) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) Collections(java.util.Collections) SellStrategy(com.github.robozonky.api.strategies.SellStrategy) SellStrategy(com.github.robozonky.api.strategies.SellStrategy) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) StrategyService(com.github.robozonky.api.strategies.StrategyService) Test(org.junit.jupiter.api.Test)

Aggregations

SellStrategy (com.github.robozonky.api.strategies.SellStrategy)3 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)2 RecommendedInvestment (com.github.robozonky.api.strategies.RecommendedInvestment)2 Optional (java.util.Optional)2 Stream (java.util.stream.Stream)2 Test (org.junit.jupiter.api.Test)2 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 InvestmentStrategy (com.github.robozonky.api.strategies.InvestmentStrategy)1 PurchaseStrategy (com.github.robozonky.api.strategies.PurchaseStrategy)1 StrategyService (com.github.robozonky.api.strategies.StrategyService)1 Events (com.github.robozonky.app.Events)1 Authenticated (com.github.robozonky.app.authentication.Authenticated)1 LoanCache (com.github.robozonky.app.util.LoanCache)1