Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Help checking if order exists
 Post subject: Help checking if order exists Post rating: 0   New post Posted: Tue 28 Apr, 2020, 20:35 
User avatar

User rating: 0
Joined: Thu 08 Aug, 2013, 17:11
Posts: 3
Location: United KingdomUnited Kingdom
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);


 
The Best Answer  Post subject: Re: Help checking if order exists Post rating: 0   New post Posted: Sat 02 May, 2020, 18:13 

User rating: 18
Joined: Thu 20 Apr, 2017, 22:42
Posts: 165
Location: Russian Federation,
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, ...)
        }


 
 Post subject: Re: Help checking if order exists Post rating: 0   New post Posted: Sun 03 May, 2020, 12:38 
User avatar

User rating: 0
Joined: Thu 08 Aug, 2013, 17:11
Posts: 3
Location: United KingdomUnited Kingdom
Thank you very much for your help


 

Jump to:  

cron
  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com