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_diagramAlso see example which applies special logic only on full order close:
https://www.dukascopy.com/wiki/#Close_Orders/Partial_close