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();
}
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()));
}
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);
}
Aggregations