在 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");
}