/**
   * @param candleSeries
   * @param startPeriod
   * @return
   * @throws ClassNotFoundException
   * @throws InstantiationException
   * @throws IllegalAccessException
   * @throws NoSuchMethodException
   * @throws InvocationTargetException
   * @throws IOException
   * @throws PersistentModelException
   * @throws StrategyRuleException
   */
  public Candle getPreviousDayCandleFromDb(CandleSeries candleSeries, ZonedDateTime startPeriod)
      throws ClassNotFoundException, InstantiationException, IllegalAccessException,
          NoSuchMethodException, InvocationTargetException, IOException, PersistentModelException,
          StrategyRuleException {
    Candle prevCandle = null;

    this.tradePersistentModel =
        (PersistentModel)
            ClassFactory.getServiceForInterface(PersistentModel._persistentModel, this);

    long days = 1;
    if (DayOfWeek.MONDAY.equals((startPeriod.getDayOfWeek()))) {
      days = 3;
    }

    ZonedDateTime newStartPeriod = this.getTradestrategy().getTradingday().getOpen();
    List<Candle> candleList =
        this.tradePersistentModel.findCandlesByContractDateRangeBarSize(
            candleSeries.getContract().getIdContract(), newStartPeriod.minusDays(days),
            newStartPeriod.minusDays(days), candleSeries.getBarSize());

    if (candleList.size() > 0) {
      prevCandle = candleList.get(0);
    }

    return prevCandle;
  }
Beispiel #2
0
 @Test
 public void testFindNotActivatedUsersByCreationDateBefore() {
   userService.removeNotActivatedUsers();
   ZonedDateTime now = ZonedDateTime.now();
   List<User> users =
       userRepository.findAllByActivatedIsFalseAndCreatedDateBefore(now.minusDays(3));
   assertThat(users).isEmpty();
 }
Beispiel #3
0
 /**
  * Not activated users should be automatically deleted after 3 days.
  *
  * <p>
  *
  * <p>This is scheduled to get fired everyday, at 01:00 (am).
  */
 @Scheduled(cron = "0 0 1 * * ?")
 public void removeNotActivatedUsers() {
   ZonedDateTime now = ZonedDateTime.now();
   List<User> users =
       userRepository.findAllByActivatedIsFalseAndCreatedDateBefore(now.minusDays(3));
   for (User user : users) {
     log.debug("Deleting not activated user {}", user.getLogin());
     userRepository.delete(user);
   }
 }