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.

Closing a partial closed order
 Post subject: Closing a partial closed order Post rating: 0   New post Posted: Wed 20 Oct, 2010, 18:52 
User avatar

User rating: 5
Joined: Fri 02 Sep, 2011, 10:08
Posts: 157
Location: FranceFrance
Hello,

I've searched in the forum but I didn't found a working solution.

I'm partialy closing an order using
order.close.(double amount)


Just to try, I did this after the partial close :

 public void onMessage(IMessage message) throws JFException {

 if (message.getType() == IMessage.Type.ORDER_CLOSE_OK) {
            IOrder closedOrder = message.getOrder();

            closedOrder.close();
        }
    }


closedOrder.close() throws this exception :

Strategy tester: com.dukascopy.api.JFException: Cannot close order in CREATED, CLOSED or CANCELED state, current state - [CLOSED] @ jforex.FXbreakoutMulti.onMessage(FXbreakoutMulti.java:134)

So how to close totally a partialy closed order since its state isn't "filled" anymore ?

Thanks


 
 Post subject: Re: Closing a partial closed order Post rating: 0   New post Posted: Thu 21 Oct, 2010, 09:59 

User rating: 0
Joined: Tue 10 Nov, 2009, 16:58
Posts: 65
support, I don't understand the answer here. the link you provide talks about partially filled orders and canceling such an order.

I want to close parts of an order, on several occasions. For example an order of 1 lot has been filled, then at some point I want to close just 0.2 of that, then later again 0.2, then the rest. All at various market prices. How can I do that since the first close() call turns the state into CLOSED and refuses the following close() calls ?

Could you be more explicit on the procedure to follow ?

Thanks

PS:Seems to me that a partially closed order should not be changed to the state CLOSED, I don't understand why the API changes the order state to CLOSED since there is still an amount left to close... so really, the order left is still in FILLED state. To me it sounds like a bug in the order lifecycle.


 
 Post subject: Re: Closing a partial closed order Post rating: 0   New post Posted: Thu 21 Oct, 2010, 10:29 

User rating: 0
Joined: Tue 10 Nov, 2009, 16:58
Posts: 65
never mind... I found the answer myself. I see the code above is not displaying the original order, but the one resulting from the partial close. One can perfectly call close() with various amounts on the original order.


 
 Post subject: Re: Closing a partial closed order Post rating: 0   New post Posted: Thu 21 Oct, 2010, 12:15 
User avatar

User rating: 5
Joined: Fri 02 Sep, 2011, 10:08
Posts: 157
Location: FranceFrance
Sorry but I didn't figure out how it works, setRequestedAmount doesn't work
on neither opened nor closed orders.

Could you please post an example based on our needs ?

Thanks


 
 Post subject: Re: Closing a partial closed order Post rating: 0   New post Posted: Tue 26 Oct, 2010, 09:46 
User avatar

User rating: 5
Joined: Fri 02 Sep, 2011, 10:08
Posts: 157
Location: FranceFrance
Please could someone give me an example ?

I really don't know how to use setRequestedAmount in order
to make partial closes of a trade.

I would like to implement this in order to comply to Novembers
strategy contest rules because at this time my strategy opens
a few pending orders with the same entry and stoploss prices
but different take profit levels. This isn't allowed...

I'm a bit in a hurry know ;)

Thanks for the support


 
 Post subject: Re: Closing a partial closed order Post rating: 0   New post Posted: Wed 27 Oct, 2010, 18:03 

User rating: 0
Joined: Tue 27 Jul, 2010, 20:57
Posts: 49
In the api-documents it's stated:
Quote:
void setRequestedAmount(double amount)
Sets amount of order in IOrder.State.OPENED state or cancels pending part of partially filled order when amount equals to zero is set

So you would have to execute .setRequestedAmount(0) on the pending (remaining) part of the order..


 

Jump to:  

cron
  © 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