コード例 #1
0
ファイル: Tutorial02.java プロジェクト: domak/algodeal
  @Override
  public void onPositionOpened(Position newPosition) {
    double entryPrice = getPosition().getUnitaryEntryPrice();
    long quantity = getPosition().getQuantity();

    barCount = 0;

    cancelOrderIfNecessary(stopSellOrder);
    cancelOrderIfNecessary(limitSellOrder);

    if (getPosition().isLong()) {
      double targetProfitExitPrice = entryPrice * (1 + limitSellExitTargetProfitPct);
      limitSellOrder = sellLimit(quantity, targetProfitExitPrice, "Exit @ Limit");

      double stopLossExitPrice = entryPrice * (1 - stopSellExitTargetProfitPct);
      stopSellOrder = sellStop(quantity, stopLossExitPrice, "Exit @ Stop");
    } else {
      double targetProfitExitPrice = entryPrice * (1 - limitSellExitTargetProfitPct);
      limitSellOrder = buyLimit(quantity, targetProfitExitPrice, "Exit @ Limit");

      double stopLossExitPrice = entryPrice * (1 + stopSellExitTargetProfitPct);
      stopSellOrder = buyStop(quantity, stopLossExitPrice, "Exit @ Stop");
    }

    limitSellOrder.setOCAGroup(getInstrument().getSymbol() + " OCA " + ocaCount);
    stopSellOrder.setOCAGroup(getInstrument().getSymbol() + " OCA " + ocaCount);
    ocaCount++;
  }
コード例 #2
0
ファイル: Tutorial02.java プロジェクト: domak/algodeal
 void cancelOrderIfNecessary(Order order) {
   if ((order != null) && !order.isCancelled() && !order.isFilled()) {
     cancelOrder(order);
   }
 }