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.

Problem with mass closing of orders
 Post subject: Problem with mass closing of orders Post rating: 0   New post Posted: Thu 05 Apr, 2012, 16:15 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
Hello,

I've written a little method to mass close all filled positions:
public void closeAllPositions(){
        try{
            List<IOrder> orders = engine.getOrders();
            List<IOrder> QFXOrders = new ArrayList<IOrder>();
            //Filter all QFX orders
            for(IOrder o : orders){
                String orderLabelHeader = (o.getLabel()).substring(0,3);
                if(orderLabelHeader.equals("QFX")){
                    if(o.getState() == IOrder.State.FILLED){
                        QFXOrders.add(o);
                    }
                }
            }
            //Close QFX orders
            if(QFXOrders.isEmpty() == false){
                engine.closeOrders(QFXOrders.toArray(new IOrder[QFXOrders.size()]));
            }
        } catch (JFException e){
            consolePrint("Error closing order: "+e);
        }
    }

This code will only close one position, since I get the following error message(this is no exception I think):
15:10:06 Mass close failed, wrong order for mass close, positionId: 35672820

What is meant with "wrong order"?

Thanks for help,
Juergen


 
 Post subject: Re: JFOREX-3691 Problem with mass closing of orders Post rating: 0   New post Posted: Fri 06 Apr, 2012, 12:18 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
Hello support,

why has this topic been moved to the bug section?
Is this really a bug or a faulty programming on my side?
Please confirm this either way since I may concentrate on other things in the meantime.

Thanks and best regards,
Juergen


 
 Post subject: Re: JFOREX-3691 Problem with mass closing of orders Post rating: 0   New post Posted: Fri 06 Apr, 2012, 12:22 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
FXjuxe wrote:
why has this topic been moved to the bug section?
This means that the issue is under investigation.


 
 Post subject: Re: JFOREX-3691 Problem with mass closing of orders Post rating: 0   New post Posted: Mon 16 Apr, 2012, 14:54 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
Hello Support,

I'm now at a point where I would need to mass close positions from my strategy.
How can I overcome this problem?
Is it ok to close all orders in a loop?
What are the disadvantages of such a solution?
Does a loop solution take more time on the trading server to close the positions than it would take with a mass close?
It would be very nice if you could provide a template solution with a loop.

Best regards,
Juergen


 
 Post subject: Re: JFOREX-3691 Problem with mass closing of orders Post rating: 0   New post Posted: Tue 17 Apr, 2012, 12:24 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
FXjuxe wrote:
Is it ok to close all orders in a loop?
Yes.
FXjuxe wrote:
What are the disadvantages of such a solution?
In principle the functionality is very similar.
FXjuxe wrote:
It would be very nice if you could provide a template solution with a loop.
See:
https://www.dukascopy.com/wiki/#Order_Management/Print_and/or_close_orders_by_group


 
 Post subject: Re: JFOREX-3691 Problem with mass closing of orders Post rating: 0   New post Posted: Tue 17 Apr, 2012, 16:01 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
Thank you for this example, I will try this.
Let me tell you that in the meantime I've made some code changes on the strategy and until now the mass closing of orders does work.
So maybe the error message was caused by a faulty programming on my side but I still don't see why.

Kind regrads,
Juergen


 
 Post subject: Re: JFOREX-3691 Problem with mass closing of orders Post rating: 0   New post Posted: Tue 15 May, 2012, 15:11 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
FXjuxe wrote:
What is meant with "wrong order"?
The reason of this message is following:
Strategy tries to close the same order(s) more than one time.

Strategy must always "wait for update" for every order when its state will change
https://www.dukascopy.com/wiki/#Manage_Order_State/Use_IOrder.waitForUpdate
E.g.:
engine.closeOrders(orders); 
            for (IOrder o : orders){
                o.waitForUpdate(2, TimeUnit.SECONDS, State.CANCELED, State.CLOSED); // wait couple of seconds for order close
            }
See more here:
https://www.dukascopy.com/wiki/#Manage_Order_State


 

Jump to:  

  © 1998-2025 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