/**
   * @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;
  }
Exemplo n.º 2
0
 /**
  * Method setUp.
  *
  * @throws java.lang.Exception
  */
 @Before
 public void setUp() throws Exception {
   TradeAppLoadConfig.loadAppProperties();
   clientId = ConfigProperties.getPropAsInt("trade.tws.clientId");
   tradeOrderHome = new TradeOrderHome();
   this.tradePersistentModel =
       (PersistentModel)
           ClassFactory.getServiceForInterface(PersistentModel._persistentModel, this);
   this.tradestrategy = TradestrategyTest.getTestTradestrategy(symbol);
   assertNotNull(this.tradestrategy);
 }