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.

How to copy order (not by reference but by value) ?
 Post subject: How to copy order (not by reference but by value) ? Post rating: 0   New post Posted: Wed 27 Jun, 2012, 10:59 

User rating: 3
Joined: Thu 28 Jul, 2011, 19:40
Posts: 72
Location: PolandPoland
I need create new order(copy existing order). How I can do this?

My problem is that I want to collect all close order in List.
I do this in this way (in onMessage method):

 public void onMessage(IMessage message) throws JFException {
         if(message.getOrder()!=null){
           IOrder order = message.getOrder();
           if(message.getType() == IMessage.Type.ORDER_CLOSE_OK){
                if(order.getOrderCommand() == IEngine.OrderCommand.BUY || order.getOrderCommand() == IEngine.OrderCommand.SELL){
                  ClosedOrder.add(order);
               }
           }
        }
    }


The problem arises when the order is partially closed, because if it is close first part, then we actually have two orders, but in the same instance (reference) and if I add second part of order to my list - ClosedOrder, then before added the first part is replaced by second part of order. (because everyting is by reference in java)

How can I add these orders so that each be treated separately?

Thanks


 
 Post subject: Re: How to copy order (not by reference but by value) ? Post rating: 0   New post Posted: Wed 27 Jun, 2012, 11:28 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Quote:
I need create new order(copy existing order). How I can do this?
Just submit order with the data of another order, e.g. (assuming the IOrder o is a closed or cancelled order, otherwise you need to set another label):
IOrder newOrder = engine.submitOrder(o.getLabel(), o.getInstrument(), o.getOrderCommand(), o.getAmount(), o.getOpenPrice());
Quote:
The problem arises when the order is partially closed, because if it is close first part, then we actually have two orders, but in the same instance (reference) and if I add second part of order to my list - ClosedOrder, then before added the first part is replaced by second part of order. (because everyting is by reference in java)

How can I add these orders so that each be treated separately?
Partially closed orders remain in state IOrder.State.FILLED, fully closed ones have state IOrder.State.CLOSED, see:
https://www.dukascopy.com/wiki/#Order_state/Market_order_states_diagram
Also see example which applies special logic only on full order close:
https://www.dukascopy.com/wiki/#Close_Orders/Partial_close


 

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