Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

Help checking if order exists
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=57330
Page 1 of 1

Author:  Predator2 [ Tue 28 Apr, 2020, 20:35 ]
Post subject:  Help checking if order exists

Hello

Can someone help me with the follwoing problem.

I would like to check if there is currently any open orders at all from my strategy. IF there is I don't want to put on anymore trades until this one either reaaches TP or SL. I'm using the bewlo code but it doesnt seem to work, can someone tell me what i'm doing wrong?
Thanks

order = engine.getOrder("MyStrategyOrder");
if(order == null && !engine.getOrders().contains(order)){

IOrder newOrder = engine.submitOrder("MyStrategyOrder" + uniqueOrderCounter++, myInstrument, myCommand, 0.01, 0, 1, stopLossPrice, takeProfitPrice);
createdOrderMap.put(newOrder, false);

Author:  mtnfx [ Sat 02 May, 2020, 18:13 ]
Post subject:  Re: Help checking if order exists

For that particular case you may use this method.
public interface IEngine {
    /**
     * Returns list of orders in {@link IOrder.State#CREATED}, {@link IOrder.State#OPENED} and {@link IOrder.State#FILLED} state
     *
     * @return list of orders
     * @throws JFException if an error occurred
     */
    List<IOrder> getOrders() throws JFException;

    /**
     * Returns list of orders in {@link IOrder.State#CREATED}, {@link IOrder.State#OPENED} and {@link IOrder.State#FILLED} state for
     * specified instrument
     *
     * @param instrument instrument
     * @return list of orders
     * @throws JFException if an error occurred
     */
    List<IOrder> getOrders(Instrument instrument) throws JFException;

Your code may look like this:
        IEngine engine = context.getEngine();
        List<IOrder> myOrders = engine.getOrders();
       
        if( myOrders.isEmpty() ) {
            DateTimeFormatter YMDHMS = DateTimeFormatter.ofPattern("yyMMdd_HHmmss");
            String uniqueLabel = "MyOrder_" + YMDHMS.format(LocalDateTime.now());
           
            engine.submitOrder(uniqueLabel, ...)
        }

Author:  Predator2 [ Sun 03 May, 2020, 12:38 ]
Post subject:  Re: Help checking if order exists

Thank you very much for your help

  Page 1 of 1