Hi Support, Please help to show how I may close multiple open orders: The current code I have for closeorder is below, but this only closes the most recent order but the previous open orders are not closed and left open.
Dear JL, Good day. I have tried the code, it did not work. I am not good at programming actually and not familiar with java coding though I have some experience with C++ long time ago. Just to give an idea, the close order command is below:
// CLOSE ORDER if(longOrder != null && closeLong) { closeOrder(longOrder); //this jumps to closeOrder - the problem it only close the latest open order while the previous are still open longOrder = null; // then it sets longOrder=null (meaning there are no more open long positions [but actually the previous long orders were not closed yet] } if(shortOrder != null && closeShort) { closeOrder(shortOrder); shortOrder = null; } }
To place order: // PLACE ORDER if (longSign) { // if longSign is true - then open a buy // if (longOrder == null) { // the longOrder==null is to check if existing there is already an open Long (I have disable so it can open more than 1 position for test) longOrder = submitOrder(OrderCommand.BUY, instrument); }
} else if (shortSign) { // if shortSign is true - then open a sell // if (shortOrder == null) { shortOrder = submitOrder(OrderCommand.SELL, instrument); } } }
And the closeOrder command is: // i think this code only closes the current position but the other open positions are not closed
And isActive(order): // i think it returns a true if order is "true" and the order state is not closed & not cancelled private boolean isActive(IOrder order) throws JFException { if (order != null && order.getState() != IOrder.State.CLOSED && order.getState() != IOrder.State.CANCELED) { return true; // return isActive == true } return false; // else return isActive == false }
I believe the problem is the closeOrder command, how to retrieve the existing open positions, is it Iorder.State.FILLED? And how to command those positions (Long or Short) to close at the same time.. Please help to advise.. Thank you very much.
Best regards, Terry
API Support
Post subject: Re: How to close multiple open orders