0

在 Interactive Brokers Java API 上,我正在尝试提交一个带有追踪止损子的订单父级。现在我可以放置一个或另一个,但不能同时放置。我怎样才能同时提交它们?我应该创建一个数组然后下订单吗?

public void sendOrder(String orderSide, int parentOrderId) {
    System.out.println("sendOrder is called");
    Order order = new Order();
    parentOrderId = nextOrderID + 1;
    order.orderId(nextOrderID + 1);
    //order.m_action = "BUY";
    order.action(orderSide);
    //order.m_totalQuantity = 1;
    order.totalQuantity(20000);
    //order.m_lmtPrice = 0.01;
    System.out.println("sendOrder, this.high = " + this.high);

    DecimalFormat df = new DecimalFormat("0.00000"); // TODO get digit according
    String formatedEntryPrice = df.format(this.high);

    System.out.println("formatedEntryPrice = " + formatedEntryPrice);

    order.lmtPrice(Double.valueOf("1.00")); // TODO stop limit at prior day high
    //order.auxPrice(this.high);
    //order.auxPrice(Double.valueOf(formatedEntryPrice));

    //order.m_orderType = "LMT";
    order.orderType("LMT");
    //order.m_account = "U1836253";
    order.account("U1836253");
  order.transmit(false);
    System.out.println("after creating order");


     if (orderSide  == "BUY"){
         Order stopLoss = new Order();
          order.action ("SELL");
        stopLoss.orderId(nextOrderID + 1);
        order.orderType ("TRAIL");
        order.totalQuantity (20000);
        order.trailingPercent (1);
        order.trailStopPrice(low);
        stopLoss.parentId(nextOrderID) ;
         order.transmit(true);
     }


     if (orderSide  == "SELL"){
         Order stopLoss = new Order();
          order.action ("BUY");
        stopLoss.orderId(nextOrderID + 1);
        order.orderType ("TRAIL");
        order.totalQuantity (20000);
        order.trailingPercent (1);
        order.trailStopPrice(low);
        stopLoss.parentId(nextOrderID) ;
         order.transmit(true);
     }





    m_s.placeOrder(nextOrderID + 1, contract, order);

    System.out.println("sendOrder is finished");
    nextOrderID = nextOrderID +1;
    client.reqIds(Integer.valueOf("1"));

    System.out.println("sendOrder is finished 2");
}
4

1 回答 1

1

您需要通过单独调用来下每个订单placeOrder。通过在父订单上设置transmitfalse,IB 将持有该订单,直到您使用 提交子订单transmit = true。IB在其 API 文档中有一个提交括号订单的示例。

请注意,您的代码似乎也是错误的,因为您正在创建一个名为的子订单,stoploss但随后您将其订单属性设置为order,这是您的父订单。我假设您实际上想要在止损单上设置这些属性。

于 2017-04-28T13:38:11.997 回答