com.dukascopy.api
Interface IOrder


public interface IOrder

Contains order data and allows order manipulation


Nested Class Summary
static class IOrder.State
          Indicates state of the order
 
Method Summary
 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)
          Compares order to current one
 double getAmount()
          Returns amount of the order.
 java.util.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
 java.lang.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 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.
 long getCreationTime()
          Returns creation time.
 java.util.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"
 java.lang.String getId()
          Returns position or entry ID
 Instrument getInstrument()
          Returns instrument of the order
 java.lang.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 Applicable to orders of state IOrder.State.OPENED.
 void setLabel(java.lang.String label)
          Sets label of order in IOrder.State.OPENED state and with conditional order command May not be called on the same order more than once per second.
 void setOpenPrice(double price)
          Sets open price for order in IOrder.State.OPENED state or pending part of partially filled order May not be called on the same order more than once per second.
 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 until order changes it's state value to one of the expected states (or to any value if expected states are not specified).
 void waitForUpdate(long timeoutMills)
          Blocks until order changes it's state, values or until timeout is elapsed (unblocks when system receives any message related to this order).
 IMessage waitForUpdate(long timeoutMills, IOrder.State... states)
          Blocks until order changes it's state value to one of the expected states (or to any value if expected states are not specified).
 IMessage waitForUpdate(long timeout, java.util.concurrent.TimeUnit unit)
          Blocks until order changes it's state, values or until timeout is elapsed (unblocks when system receives any message related to this order).
 IMessage waitForUpdate(long timeout, java.util.concurrent.TimeUnit unit, IOrder.State... states)
          Blocks until order changes it's state value to one of the expected states (or to any value if expected states are not specified).
 

Method Detail

getInstrument

Instrument getInstrument()
Returns instrument of the order

Returns:
instrument

getLabel

java.lang.String getLabel()
Returns label

Returns:
label

getId

java.lang.String getId()
Returns position or entry ID

Returns:
id

getCreationTime

long getCreationTime()
Returns creation time. This is the time when server accepted the order, not the time when it was submitted

Returns:
creation time

getCloseTime

long getCloseTime()
Returns time when server closed the order

Returns:
time when order was closed

getOrderCommand

IEngine.OrderCommand getOrderCommand()
Returns IEngine.OrderCommand of this message. After the order fill returns IEngine.OrderCommand.BUY if the order is LONG, IEngine.OrderCommand.SELL otherwise.

Returns:
order command of this message

isLong

boolean isLong()
Returns true if order is LONG. Equals to getOrderCommand().isLong()

Returns:
true if order is LONG

getFillTime

long getFillTime()
Returns time of the fill

Returns:
time of the order fill

getOriginalAmount

double getOriginalAmount()
Returns original constant amount of the order. The value is set on order submit and cannot be changed later.

Returns:
original amount of the order
See Also:
IEngine.submitOrder(String, Instrument, com.dukascopy.api.IEngine.OrderCommand, double)

getAmount

double getAmount()
Returns amount of the order. For orders in 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).

Returns:
amount of the order

getRequestedAmount

double getRequestedAmount()
Returns requested amount

Returns:
amount requested

getOpenPrice

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

Returns:
entry level for conditional orders or open price for positions

getClosePrice

double getClosePrice()
Returns price at which order was closed or 0 if order or order part wasn't closed. This is the price of latest close operation in case of partial close

Returns:
close price for closed orders, return 0 for any other type of order

getStopLossPrice

double getStopLossPrice()
Returns price of stop loss condition or 0 if stop loss condition is not set. Orders submitted with stop loss condition, will have this price set only after server accepts order

Returns:
stop loss price or 0

getTakeProfitPrice

double getTakeProfitPrice()
Returns price of take profit condition or 0 if take profit condition is not set. Orders submitted with take profit condition, will have this price set only after server accepts order

Returns:
take profit price or 0

setStopLossPrice

void setStopLossPrice(double price)
                      throws JFException
Sets stop loss price. If price is 0 or negative, then stop loss condition will be removed. Default stop loss side is BID for long orders and ASK for short. This method will send command to the server, 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. May not be called on the same order more than once per second.

Parameters:
price - price to set
Throws:
JFException - when method fails for some reason

setStopLossPrice

void setStopLossPrice(double price,
                      OfferSide side)
                      throws JFException
Sets stop loss price. If price is 0 or negative, then stop loss condition will be removed. This method will send command to the server, 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. May not be called on the same order more than once per second.

Parameters:
price - price to set
side - side that will be used to check stop loss condition
Throws:
JFException - when method fails for some reason

setStopLossPrice

void setStopLossPrice(double price,
                      OfferSide side,
                      double trailingStep)
                      throws JFException
Sets stop loss price. If price is 0 or negative, then stop loss condition will be removed. If trailingStep is bigger than 10, then trailing step logic will be applied for stop loss price. This method will send command to the server, 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. May not be called on the same order more than once per second.

Parameters:
price - price to set
side - side that will be used to check stop loss condition
trailingStep - if < 0 then adds stop loss order without trailing step. Should be 0 or >= 10
Throws:
JFException - trailingStep is > 0 and < 10 or when method fails for some reason

setLabel

void setLabel(java.lang.String label)
              throws JFException
Sets label of order in IOrder.State.OPENED state and with conditional order command

May not be called on the same order more than once per second.

Parameters:
label - new label
Throws:
JFException - if order is not in IOrder.State.OPENED state or new label is null or empty

getStopLossSide

OfferSide getStopLossSide()
Returns side that is used to check stop loss condition

Returns:
stop loss side

getTrailingStep

double getTrailingStep()
Returns current trailing step or 0 if no trailing step is set

Returns:
trailing step value

setTakeProfitPrice

void setTakeProfitPrice(double price)
                        throws JFException
Sets take profit price. If price is 0 or negative, then take profit condition will be removed. This method will send command to the server, 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. May not be called on the same order more than once per second.

Parameters:
price - price to set
Throws:
JFException - when method fails for some reason

getComment

java.lang.String getComment()
Returns comment that was set when order was submitted

Returns:
comment

setRequestedAmount

void setRequestedAmount(double amount)
                        throws JFException
Sets amount of order in IOrder.State.OPENED state or cancels pending part of partially filled order when amount equals to zero is set.

May not be called on the same order more than once per second.

Parameters:
amount - new amount
Throws:
JFException - if order is not in IOrder.State.OPENED state or amount is not 0 for IOrder.State.FILLED state or if amount is less than a minimum allowed

setOpenPrice

void setOpenPrice(double price)
                  throws JFException
Sets open price for order in IOrder.State.OPENED state or pending part of partially filled order

May not be called on the same order more than once per second.

Parameters:
price - price of the opening condition
Throws:
JFException - when price change fails

close

void close(double amount,
           double price,
           double slippage)
           throws JFException
Sends a request to close the position with specified amount, price and slippage. If order has both pending and filled parts and amount is greater than 0, only filled part will be closed. If amount is 0 then both filled and pending parts will be closed/canceled.

Applicable to orders of state IOrder.State.OPENED and IOrder.State.FILLED

Parameters:
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 closed
price - 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.
Throws:
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 >= 0

close

void close(double amount,
           double price)
           throws JFException
Sends a request to close the position with specified amount, price and default slippage. If order has both pending and filled parts and amount is greater than 0, only filled part will be closed. If amount is 0 then both filled and pending parts will be closed/canceled.

Applicable to orders of state IOrder.State.OPENED and IOrder.State.FILLED

Parameters:
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 closed
price - required close price. Close will be rejected if no liquidity at this price. This parameter doesn't affect entry (conditional) orders.
Throws:
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

close

void close(double amount)
           throws JFException
Sends a request to close the position with specified amount, by market price and default slippage. If order has both pending and filled parts and amount is greater than 0, only filled part will be closed. If amount is 0 then both filled and pending parts will be closed/canceled.

Applicable to orders of state IOrder.State.OPENED and IOrder.State.FILLED

Parameters:
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 closed
Throws:
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

close

void close()
           throws JFException
Sends a request to fully close position by market price or cancel entry order. If order has both pending and filled parts, both will be closed/canceled.

Applicable to orders of state IOrder.State.OPENED and IOrder.State.FILLED This is the only allowed close() method for entry orders

Throws:
JFException

getState

IOrder.State getState()
Returns current IOrder.State of the order

Returns:
state

setGoodTillTime

void setGoodTillTime(long goodTillTime)
                     throws JFException
Sets "good till time" for BIDs, OFFERs and LIMIT orders

Applicable to orders of state IOrder.State.OPENED. May not be called on the same order more than once per second.

Parameters:
goodTillTime - time when BID, OFFER or LIMIT orders should be canceled
Throws:
JFException - when order is simple market order

getGoodTillTime

long getGoodTillTime()
Returns time when order will be cancelled or 0 if order is "good till cancel"

Returns:
cancel time or 0

waitForUpdate

void waitForUpdate(long timeoutMills)
Blocks until order changes it's state, values or until timeout is elapsed (unblocks when system receives any message related to this order). All the ticks and bars that platform received while waiting will be dropped. Method shouldn't be used for waiting long running events, like closing the order by stop loss, else buffer with messages will overflow and strategy will be stopped.

Parameters:
timeoutMills - timeout to wait for order state change

waitForUpdate

IMessage waitForUpdate(long timeout,
                       java.util.concurrent.TimeUnit unit)
Blocks until order changes it's state, values or until timeout is elapsed (unblocks when system receives any message related to this order). All the ticks and bars that platform received while waiting will be dropped. Method shouldn't be used for waiting long running events, like closing the order by stop loss, else buffer with messages will overflow and strategy will be stopped. Method returns message related to order update, which can be especially useful when order state doesn't change (operation was rejected)

Parameters:
timeout - how long to wait before giving up, in units of unit
unit - a TimeUnit determining how to interpret the timeout parameter
Returns:
message generated as the result of order update or null if method exited by timeout

waitForUpdate

IMessage waitForUpdate(IOrder.State... states)
                       throws JFException
Blocks until order changes it's state value to one of the expected states (or to any value if expected states are not specified).
(unblocks when system receives message related to this order which changes order's state to one of expected).
All the ticks and bars that platform received while waiting will be dropped.
Method shouldn't be used for waiting long running events, like closing the order by stop loss, else buffer with messages will overflow and strategy will be stopped.
The real time is not taken into consideration and the order simply waits until its state changes to one of the specified expected states or
JFException will be thrown due to order is in state that cannot be changed to one of expected ones.

Parameters:
states - a set of expected states. If null or empty - blocks until order changes it's state to any value.
Returns:
message generated as the result of order update. Can be null if method exited by timeout
Throws:
JFException - when order is in state that cannot be changed to one of expected states

waitForUpdate

IMessage waitForUpdate(long timeoutMills,
                       IOrder.State... states)
                       throws JFException
Blocks until order changes it's state value to one of the expected states (or to any value if expected states are not specified).
(unblocks when system receives message related to this order which changes order's state to one of expected).
All the ticks and bars that platform received while waiting will be dropped.
Method shouldn't be used for waiting long running events, like closing the order by stop loss, else buffer with messages will overflow and strategy will be stopped.

Parameters:
timeoutMills - timeout to wait for order state change
states - a set of expected states. If null or empty - blocks until order changes it's state to any value.
Returns:
message generated as the result of order update. Can be null if method exited by timeout
Throws:
JFException - when order is in state that cannot be changed to one of expected states

waitForUpdate

IMessage waitForUpdate(long timeout,
                       java.util.concurrent.TimeUnit unit,
                       IOrder.State... states)
                       throws JFException
Blocks until order changes it's state value to one of the expected states (or to any value if expected states are not specified).
(unblocks when system receives message related to this order which changes order's state to one of expected).
All the ticks and bars that platform received while waiting will be dropped.
Method shouldn't be used for waiting long running events, like closing the order by stop loss, else buffer with messages will overflow and strategy will be stopped.
Method returns message related to order update.

Parameters:
timeout - how long to wait before giving up, in units of unit
unit - 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.
Returns:
message generated as the result of order update. Can be null if method exited by timeout
Throws:
JFException - when order is in state that cannot be changed to one of expected states

getProfitLossInPips

double getProfitLossInPips()
Returns profit/loss in pips

Returns:
profit/loss in pips

getProfitLossInUSD

double getProfitLossInUSD()
Returns profit/loss in USD

Returns:
profit/loss in USD

getProfitLossInAccountCurrency

double getProfitLossInAccountCurrency()
Returns profit/loss in account currency

Returns:
profit/loss in account currency

getCommission

double getCommission()
Return position's commission in account currency.

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.

Returns:
position's commission in account currency

getCommissionInUSD

double getCommissionInUSD()
Return position's commission in USD

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.

Returns:
position's commission in USD

getFillHistory

java.util.List<IFillOrder> getFillHistory()
Returns ordered history of order filling. History is sorted by fill time in ascending order.

Returns:
ascending ordered history of order filling

getCloseHistory

java.util.List<ICloseOrder> getCloseHistory()
Returns ordered history of order closing. History is sorted by close time in ascending order.

Returns:
ascending ordered history of order closing

compare

boolean compare(IOrder order)
Compares order to current one

Parameters:
order - to compare with current
Returns:
true if all fields are equal