public interface IOrder
Modifier and Type | Interface and Description |
---|---|
static class |
IOrder.State
Indicates state of the order
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Sends a request to fully close position by market price or cancel entry order.
|
void |
close(double amount)
Sends a request to close the position with specified amount, by market price and default slippage.
|
void |
close(double amount,
double price)
Sends a request to close the position with specified amount, price and default slippage.
|
void |
close(double amount,
double price,
double slippage)
Sends a request to close the position with specified amount, price and slippage.
|
boolean |
compare(IOrder order)
Deprecated.
|
double |
getAmount()
Returns amount of the order.
|
List<ICloseOrder> |
getCloseHistory()
Returns ordered history of order closing.
|
double |
getClosePrice()
Returns price at which order was closed or 0 if order or order part wasn't closed.
|
long |
getCloseTime()
Returns time when server closed the order
|
String |
getComment()
Returns comment that was set when order was submitted
|
double |
getCommission()
Return position's commission in account currency.
|
double |
getCommissionInUSD()
Return position's commission in USD
|
long |
getCreationTime()
Returns creation time.
|
List<IFillOrder> |
getFillHistory()
Returns ordered history of order filling.
|
long |
getFillTime()
Returns time of the fill
|
long |
getGoodTillTime()
Returns time when order will be cancelled or 0 if order is "good till cancel"
|
String |
getId()
Returns position or entry ID
|
Instrument |
getInstrument()
Returns instrument of the order
|
String |
getLabel()
Returns label
|
double |
getOpenPrice()
Returns entry level price for conditional orders in
IOrder.State.CREATED and IOrder.State.OPENED state or price at which order was
filled for orders in IOrder.State.FILLED or IOrder.State.CLOSED states |
IEngine.OrderCommand |
getOrderCommand()
Returns
IEngine.OrderCommand of this message. |
double |
getOriginalAmount()
Returns original constant amount of the order.
|
double |
getProfitLossInAccountCurrency()
Returns profit/loss in account currency
|
double |
getProfitLossInPips()
Returns profit/loss in pips.
|
double |
getProfitLossInUSD()
Returns profit/loss in USD
|
double |
getRequestedAmount()
Returns requested amount
|
IOrder.State |
getState()
Returns current
IOrder.State of the order |
double |
getStopLossPrice()
Returns price of stop loss condition or 0 if stop loss condition is not set.
|
OfferSide |
getStopLossSide()
Returns side that is used to check stop loss condition
|
double |
getTakeProfitPrice()
Returns price of take profit condition or 0 if take profit condition is not set.
|
double |
getTrailingStep()
Returns current trailing step or 0 if no trailing step is set
|
boolean |
isLong()
Returns true if order is LONG.
|
void |
setGoodTillTime(long goodTillTime)
Sets "good till time" for BIDs, OFFERs and LIMIT orders.
|
void |
setLabel(String label)
Sets label for entry orders.
|
void |
setOpenPrice(double price)
Sets open price for order in
IOrder.State.OPENED state or pending part of partially filled order |
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. |
void |
setStopLossPrice(double price)
Sets stop loss price.
|
void |
setStopLossPrice(double price,
OfferSide side)
Sets stop loss price.
|
void |
setStopLossPrice(double price,
OfferSide side,
double trailingStep)
Sets stop loss price.
|
void |
setTakeProfitPrice(double price)
Sets take profit price.
|
IMessage |
waitForUpdate(IOrder.State... states)
Blocks strategy thread (with exception of
IStrategy.onMessage(IMessage) ) until the order changes it's state value to one of the expected states. |
void |
waitForUpdate(long timeoutMills)
Blocks strategy thread (with exception of
IStrategy.onMessage(IMessage) ) until the order changes it's state or any order value gets updated. |
IMessage |
waitForUpdate(long timeoutMills,
IOrder.State... states)
Blocks strategy thread (with exception of
IStrategy.onMessage(IMessage) ) until the order changes it's state value to one of the expected states. |
IMessage |
waitForUpdate(long timeout,
TimeUnit unit)
Blocks strategy thread (with exception of
IStrategy.onMessage(IMessage) ) until the order changes it's state or any order value gets updated. |
IMessage |
waitForUpdate(long timeout,
TimeUnit unit,
IOrder.State... states)
Blocks strategy thread (with exception of
IStrategy.onMessage(IMessage) ) until the order changes it's state value to one of the expected states. |
Instrument getInstrument()
String getLabel()
String getId()
long getCreationTime()
long getCloseTime()
IEngine.OrderCommand getOrderCommand()
IEngine.OrderCommand
of this message.
After the order fill returns IEngine.OrderCommand.BUY
if the order is LONG,
IEngine.OrderCommand.SELL
otherwise.boolean isLong()
getOrderCommand().isLong()
long getFillTime()
double getOriginalAmount()
IEngine.submitOrder(String, Instrument, com.dukascopy.api.IEngine.OrderCommand, double)
double getAmount()
IOrder.State.OPENED
state returns amount requested. For orders in IOrder.State.FILLED
state will return filled amount. Filled amount can be different from requested amount (partial fill).double getRequestedAmount()
double getOpenPrice()
IOrder.State.CREATED
and IOrder.State.OPENED
state or price at which order was
filled for orders in IOrder.State.FILLED
or IOrder.State.CLOSED
statesdouble getClosePrice()
double getStopLossPrice()
double getTakeProfitPrice()
void setStopLossPrice(double price) throws JFException
getStopLossPrice()
method will still return old value until server
will accept this changes.
Applicable to orders of state IOrder.State.OPENED
and IOrder.State.FILLED
. By default, may not be called on the same order more often than once per second
(exact value of max order update per second is sent by server).
Not applicable for Global accounts.
if (order.getState() == IOrder.State.FILLED || (order.getState() == IOrder.State.OPENED && order.getOrderCommand().isConditional()) ) { order.setStopLossPrice(order.getOpenPrice() - instrument.getPipValue() * 20); }
price
- price to setJFException
- when method fails for some reasonvoid setStopLossPrice(double price, OfferSide side) throws JFException
getStopLossPrice()
method will still return old value until server will accept this changes
Applicable to orders of state IOrder.State.OPENED
and IOrder.State.FILLED
. By default, may not be called on the same order more often than once per second
(exact value of max order update per second is sent by server).
Not applicable for Global accounts.
if (order.getState() == IOrder.State.FILLED || (order.getState() == IOrder.State.OPENED && order.getOrderCommand().isConditional()) ) { order.setStopLossPrice(order.getOpenPrice() - instrument.getPipValue() * 20, OfferSide.BID); }
price
- price to setside
- side that will be used to check stop loss conditionJFException
- when method fails for some reasonvoid setStopLossPrice(double price, OfferSide side, double trailingStep) throws JFException
getStopLossPrice()
method will still
return old value until server will accept this changes
Applicable to orders of state IOrder.State.OPENED
and IOrder.State.FILLED
. By default, may not be called on the same order more often than once per second
(exact value of max order update per second is sent by server).
Not applicable for Global accounts.
if (order.getState() == IOrder.State.FILLED || (order.getState() == IOrder.State.OPENED && order.getOrderCommand().isConditional()) ) { order.setStopLossPrice(order.getOpenPrice() - instrument.getPipValue() * 20, OfferSide.BID, 10); }
price
- price to setside
- side that will be used to check stop loss conditiontrailingStep
- if < 0 then adds stop loss order without trailing step. Should be 0 or >= 10JFException
- trailingStep is > 0 and < 10 or when method fails for some reasonvoid setLabel(String label) throws JFException
By default, may not be called on the same order more often than once per second (exact value of max order update per second is sent by server).
if (order.getState() == IOrder.State.OPENED && order.getOrderCommand().isConditional()) { order.setLabel("new_"+order.getLabel()); }
label
- new labelJFException
- if order is not in IOrder.State.OPENED
state or new label is null or emptyOfferSide getStopLossSide()
double getTrailingStep()
void setTakeProfitPrice(double price) throws JFException
getTakeProfitPrice()
method will still return old value until server will accept this changes
Applicable to orders of state IOrder.State.OPENED
and IOrder.State.FILLED
. By default, may not be called on the same order more often than once per second
(exact value of max order update per second is sent by server).
Not applicable for Global accounts.
if (order.getState() == IOrder.State.FILLED || (order.getState() == IOrder.State.OPENED && order.getOrderCommand().isConditional()) ) { order.setTakeProfitPrice(order.getOpenPrice() + instrument.getPipValue() * 20); }
price
- price to setJFException
- when method fails for some reasonString getComment()
void setRequestedAmount(double amount) throws JFException
IOrder.State.OPENED
state or cancels pending part of partially
filled order when amount equals to zero is set.
By default, may not be called on the same order more often than once per second (exact value of max order update per second is sent by server).
if (order.getState() == IOrder.State.OPENED && order.getOrderCommand().isConditional()) { order.setRequestedAmount(0); //cancel conditional order } if (order.getState() == IOrder.State.OPENED && order.getOrderCommand().isConditional()) { order.setRequestedAmount(order.getAmount() * 2); //double the order amount }
amount
- new amountJFException
- when:
IOrder.State.OPENED
nor IOrder.State.FILLED
IOrder.State.OPENED
and amount is less than the minimum allowed and not 0IOrder.State.FILLED
and with getRequestedAmount()
==getAmount()
IOrder.State.FILLED
and the amount is not 0void setOpenPrice(double price) throws JFException
IOrder.State.OPENED
state or pending part of partially filled order
By default, may not be called on the same order more often than once per second (exact value of max order update per second is sent by server).
if (order.getState() == IOrder.State.OPENED && order.getOrderCommand().isConditional()) { //raise open price by two pips order.setOpenPrice(order.getOpenPrice() + order.getInstrument().getPipValue() * 2); } if (order.getState() == IOrder.State.FILLED && order.getOrderCommand().isConditional() && order.getAmount() < order.getRequestedAmount() ) { //change open price for the UNFILLED part order.setOpenPrice(order.getOpenPrice() + order.getInstrument().getPipValue() * 2); }
price
- price of the opening conditionJFException
- when price change failsvoid close(double amount, double price, double slippage) throws JFException
Applicable to orders of state IOrder.State.OPENED
and IOrder.State.FILLED
. Full position close is not allowed for Global accounts.
if (order.getState() == IOrder.State.FILLED) { // conditional partial close by price, with default slippage of 1 pip double lastBid = history.getLastTick(instrument).getBid(); order.close(0.003, lastBid - 1 * instrument.getPipValue(), 1); }
amount
- closing amount. Can be less than opened amount, in this case partial close will take place. If 0 is provided then all
amount will be closedprice
- required close price. Close will be rejected if no liquidity at this price. This parameter doesn't affect
entry (conditional) orders.slippage
- required price slippage. The value of slippage means following:
JFException
- when called for order not in IOrder.State.OPENED
or IOrder.State.FILLED
state.
And if order is IOrder.State.OPENED
, but amount != 0 or price != 0 or slippage >= 0void close(double amount, double price) throws JFException
Applicable to orders of state IOrder.State.OPENED
and IOrder.State.FILLED
. Full position close is not allowed for Global accounts.
Note: default value of 5 pips slippage is used. To specify custom slippage, or disable slippage at all, please use extended close(...)
methods.
if (order.getState() == IOrder.State.FILLED) { // conditional partial close by price, with default slippage of 5 pips double lastBid = history.getLastTick(instrument).getBid(); order.close(0.003, lastBid - 1 * instrument.getPipValue()); }Note: default value of 5 pips slippage is used. To specify custom slippage, or disable slippage at all, please use extended
close(...)
methods.amount
- closing amount. Can be less than opened amount, in this case partial close will take place. If 0 is provided then all
amount will be closedprice
- required close price. Close will be rejected if no liquidity at this price. This parameter doesn't affect
entry (conditional) orders.JFException
- when called for order not in IOrder.State.OPENED
or IOrder.State.FILLED
state.
And if order is IOrder.State.OPENED
, but amount != 0 or price != 0void close(double amount) throws JFException
Applicable to orders of state IOrder.State.OPENED
and IOrder.State.FILLED
. Full position close is not allowed for Global accounts.
if (order.getState() == IOrder.State.FILLED) { // unconditional partial close order.close(order.getAmount() / 2); }
amount
- closing amount. Can be less than opened amount, in this case partial close will take place. If 0 is provided then all
amount will be closedJFException
- when called for order not in IOrder.State.OPENED
or IOrder.State.FILLED
state.
And if order is IOrder.State.OPENED
, but amount != 0void close() throws JFException
Applicable to orders of state IOrder.State.OPENED
and IOrder.State.FILLED
. Not allowed for Global accounts.
if (order.getState() == IOrder.State.FILLED) { // unconditional close order.close(); } if (order.getState() == IOrder.State.OPENED && order.getOrderCommand().isConditional()) { // cancel conditional order order.close(); }
JFException
IOrder.State getState()
IOrder.State
of the ordervoid setGoodTillTime(long goodTillTime) throws JFException
Applicable to orders of state IOrder.State.OPENED
. By default, may not be called on the same order more often than once per second
(exact value of max order update per second is sent by server).
//order "expires" 1 minute after its creation if (order.getState() == IOrder.State.OPENED && order.getOrderCommand().isConditional()) { order.setGoodTillTime(order.getCreationTime() + TimeUnit.MINUTES.toMillis(1)); }
goodTillTime
- time when BID, OFFER or LIMIT orders should be canceledJFException
- when order is simple market orderlong getGoodTillTime()
void waitForUpdate(long timeoutMills)
IStrategy.onMessage(IMessage)
) until the order changes it's state or any order value gets updated.
All the ticks, bars and other feed elements that platform receives while waiting get dropped.
The method should be used for imminent order updates (e.g., set stop loss, close order). Consequently it should not be used for non-imminent order updates
like order close on stop loss, conditional order fill, etc.
The method must not be called from the IStrategy.onMessage(IMessage)
method.
See usage example at waitForUpdate(long, TimeUnit, State...)
timeoutMills
- timeout to wait for order state changeIMessage waitForUpdate(long timeout, TimeUnit unit)
IStrategy.onMessage(IMessage)
) until the order changes it's state or any order value gets updated.
All the ticks, bars and other feed elements that platform receives while waiting get dropped.
The method should be used for imminent order updates (e.g., set stop loss, close order). Consequently it should not be used for non-imminent order updates
like order close on stop loss, conditional order fill, etc.
The method must not be called from the IStrategy.onMessage(IMessage)
method.
See usage example at waitForUpdate(long, TimeUnit, State...)
timeout
- how long to wait before giving up, in units of
unitunit
- a TimeUnit determining how to interpret the
timeout parameterIMessage waitForUpdate(IOrder.State... states) throws JFException
IStrategy.onMessage(IMessage)
) until the order changes it's state value to one of the expected states.
If states is empty, any order update will cause the thread unblocking.
All the ticks, bars and other feed elements that platform receives while waiting get dropped.
The method should be used for imminent order updates (e.g., set stop loss, close order). Consequently it should not be used for non-imminent order updates
like order close on stop loss, conditional order fill, etc.
The method must not be called from the IStrategy.onMessage(IMessage)
method.
See usage example at waitForUpdate(long, TimeUnit, State...)
states
- a set of expected states. If null or empty - blocks until order changes it's state to any value.JFException
- when order is in state that cannot be changed to one of expected statesIMessage waitForUpdate(long timeoutMills, IOrder.State... states) throws JFException
IStrategy.onMessage(IMessage)
) until the order changes it's state value to one of the expected states.
If states is empty, any order update will cause the thread unblocking.
All the ticks, bars and other feed elements that platform receives while waiting get dropped.
The method should be used for imminent order updates (e.g., set stop loss, close order). Consequently it should not be used for non-imminent order updates
like order close on stop loss, conditional order fill, etc.
The method must not be called from the IStrategy.onMessage(IMessage)
method.
See usage example at waitForUpdate(long, TimeUnit, State...)
timeoutMills
- timeout to wait for order state changestates
- a set of expected states. If null or empty - blocks until order changes it's state to any value.JFException
- when order is in state that cannot be changed to one of expected statesIMessage waitForUpdate(long timeout, TimeUnit unit, IOrder.State... states) throws JFException
IStrategy.onMessage(IMessage)
) until the order changes it's state value to one of the expected states.
If states is empty, any order update will cause the thread unblocking.
All the ticks, bars and other feed elements that platform receives while waiting get dropped.
The method should be used for imminent order updates (e.g., set stop loss, close order). Consequently it should not be used for non-imminent order updates
like order close on stop loss, conditional order fill, etc.
The method must not be called from the IStrategy.onMessage(IMessage)
method.
public void onStart(IContext context) throws JFException { IEngine engine = context.getEngine(); IConsole console = context.getConsole(); context.setSubscribedInstruments(java.util.Collections.singleton(Instrument.EURUSD), true); //submit order and await its fill data IOrder o = engine.submitOrder("order", Instrument.EURUSD, OrderCommand.BUY, 0.001); o.waitForUpdate(2, TimeUnit.SECONDS, IOrder.State.FILLED); console.getOut().format("After fill: open price=%.5f, fill time=%s", o.getOpenPrice(), DateUtils.format(o.getFillTime())).println(); //adjust stop loss to be in 5 pip distance from open price and await the assigned SL price o.setStopLossPrice(o.getOpenPrice() - 0.0005); //wait max 2 sec for SL price to get updated; note that we don't expect IOrder.State change here o.waitForUpdate(2, TimeUnit.SECONDS); console.getOut().format("After SL update: stop loss=%.5f", o.getStopLossPrice()).println(); }
timeout
- how long to wait before giving up, in units of
unitunit
- a TimeUnit determining how to interpret the
timeout parameter.states
- a set of expected states. If null or empty - blocks until order changes it's state to any value.JFException
- when order is in state that cannot be changed to one of expected statesdouble getProfitLossInPips()
double getProfitLossInUSD()
double getProfitLossInAccountCurrency()
double getCommission()
For global accounts (i.e., IAccount.isGlobal()
) returns the accumulated commission
of the instrument's position that has been accumulated over the current trading session.
Which means that the value gets reset with every platform reconnect.
double getCommissionInUSD()
For global accounts (i.e., IAccount.isGlobal()
) returns the accumulated commission
of the instrument's position that has been accumulated over the current trading session.
Which means that the value gets reset with every platform reconnect.
List<IFillOrder> getFillHistory()
List<ICloseOrder> getCloseHistory()
@Deprecated boolean compare(IOrder order)
Object.equals(Object)
order
- to compare with currentCopyright © 2016. All rights reserved.