171 lines
6.8 KiB
Java
171 lines
6.8 KiB
Java
package ats.orders;
|
||
|
||
import com.oanda.v20.order.OrderTriggerCondition;
|
||
|
||
import org.joda.time.DateTime;
|
||
|
||
/**
|
||
* Create a new market-if-touched order request to send to the OANDA API.
|
||
*
|
||
* @see <a href="https://developer.oanda.com/rest-live-v20/order-df/#MarketIfTouchedOrderRequest">OANDA API docs</a>
|
||
*/
|
||
public class TakeProfitOrderRequest extends OrderRequest {
|
||
|
||
/**
|
||
* The ID of the Trade to close when the price threshold is
|
||
* breached.
|
||
*/
|
||
public String tradeID;
|
||
|
||
/**
|
||
* The client ID of the Trade to be closed when the price
|
||
* threshold is breached.
|
||
*/
|
||
public String clientTradeID;
|
||
|
||
/**
|
||
* The price threshold specified for the TakeProfit Order. The
|
||
* associated Trade will be closed by a market price that is equal
|
||
* to or better than this threshold.
|
||
*/
|
||
public String price;
|
||
|
||
/**
|
||
* The time-in-force requested for the TakeProfit
|
||
* Order. Restricted to “GTC”, “GFD” and “GTD” for TakeProfit
|
||
* Orders. The default is TimeInForce.GTC.
|
||
*/
|
||
public TimeInForce timeInForce;
|
||
|
||
/**
|
||
* The date/time when the order will be cancelled if its
|
||
* timeInForce is “GTD”.
|
||
*/
|
||
public DateTime gtdTime;
|
||
|
||
/**
|
||
* Specification of which price component should be used when
|
||
* determining if an Order should be triggered and filled. This
|
||
* allows Orders to be triggered based on the bid, ask, mid,
|
||
* default (ask for buy, bid for sell) or inverse (ask for sell,
|
||
* bid for buy) price depending on the desired behaviour. Orders
|
||
* are always filled using their default price component. This
|
||
* feature is only provided through the REST API. Clients who
|
||
* choose to specify a non-default trigger condition will not see
|
||
* it reflected in any of OANDA’s proprietary or partner trading
|
||
* platforms, their transaction history or their account
|
||
* statements. OANDA platforms always assume that an Order’s
|
||
* trigger condition is set to the default value when indicating
|
||
* the distance from an Order’s trigger price, and will always
|
||
* provide the default trigger condition when creating or
|
||
* modifying an Order. A special restriction applies when creating
|
||
* a guaranteed Stop Loss Order. In this case the TriggerCondition
|
||
* value must either be “DEFAULT”, or the “natural” trigger side
|
||
* “DEFAULT” results in. So for a Stop Loss Order for a long trade
|
||
* valid values are “DEFAULT” and “BID”, and for short trades
|
||
* “DEFAULT” and “ASK” are valid. The default is
|
||
* OrderTriggerCondition.DEFAULT.
|
||
*/
|
||
public OrderTriggerCondition triggerCondition;
|
||
|
||
/**
|
||
* The client extensions to add to the Order. Do not set, modify,
|
||
* or delete clientExtensions if your account is associated with
|
||
* MT4.
|
||
*/
|
||
public ClientExtensions clientExtensions;
|
||
|
||
|
||
|
||
/**
|
||
* Create a new take profit order request to send to the OANDA
|
||
* API.
|
||
*
|
||
* @param tradeID The ID of the Trade to close when the price
|
||
* threshold is breached.
|
||
*
|
||
* @param clientTradeID The client ID of the Trade to be closed
|
||
* when the price threshold is breached.
|
||
*
|
||
* @param price The price threshold specified for the TakeProfit
|
||
* Order. The associated Trade will be closed by a market price
|
||
* that is equal to or better than this threshold.
|
||
*/
|
||
public TakeProfitOrderRequest(String tradeID, String clientTradeID, String price)
|
||
{
|
||
this(tradeID, clientTradeID, price, null, null, null, null);
|
||
}
|
||
|
||
/**
|
||
* Create a new take profit order request to send to the OANDA
|
||
* API.
|
||
*
|
||
* @param tradeID The ID of the Trade to close when the price
|
||
* threshold is breached.
|
||
*
|
||
* @param clientTradeID The client ID of the Trade to be closed
|
||
* when the price threshold is breached.
|
||
*
|
||
* @param price The price threshold specified for the TakeProfit
|
||
* Order. The associated Trade will be closed by a market price
|
||
* that is equal to or better than this threshold.
|
||
*
|
||
* @param timeInForce The time-in-force requested for the Order.
|
||
* Restricted to “GTC”, “GFD” and “GTD” for TakeProfit Orders.
|
||
* The default is TimeInForce.GTC.
|
||
*
|
||
* @param gtdTime The date when the Order will be cancelled on if
|
||
* timeInForce is GTD.
|
||
*
|
||
* @param triggerCondition Specification of which price component
|
||
* should be used when determining if an Order should be triggered
|
||
* and filled. This allows Orders to be triggered based on the
|
||
* bid, ask, mid, default (ask for buy, bid for sell) or inverse
|
||
* (ask for sell, bid for buy) price depending on the desired
|
||
* behaviour. Orders are always filled using their default price
|
||
* component. This feature is only provided through the REST
|
||
* API. Clients who choose to specify a non-default trigger
|
||
* condition will not see it reflected in any of OANDA’s
|
||
* proprietary or partner trading platforms, their transaction
|
||
* history or their account statements. OANDA platforms always
|
||
* assume that an Order’s trigger condition is set to the default
|
||
* value when indicating the distance from an Order’s trigger
|
||
* price, and will always provide the default trigger condition
|
||
* when creating or modifying an Order. A special restriction
|
||
* applies when creating a guaranteed Stop Loss Order. In this
|
||
* case the TriggerCondition value must either be “DEFAULT”, or
|
||
* the “natural” trigger side “DEFAULT” results in. So for a Stop
|
||
* Loss Order for a long trade valid values are “DEFAULT” and
|
||
* “BID”, and for short trades “DEFAULT” and “ASK” are valid.
|
||
* The default is OrderTriggerCondition.DEFAULT.
|
||
*
|
||
* @param clientExtensions The client extensions to add to the
|
||
* Order. Do not set, modify, or delete clientExtensions if your
|
||
* account is associated with MT4.
|
||
*/
|
||
public TakeProfitOrderRequest(String tradeID,
|
||
String clientTradeID,
|
||
String price,
|
||
TimeInForce timeInForce,
|
||
DateTime gtdTime,
|
||
OrderTriggerCondition triggerCondition,
|
||
ClientExtensions clientExtensions)
|
||
{
|
||
super(OrderType.TAKE_PROFIT);
|
||
|
||
this.tradeID = tradeID;
|
||
this.clientTradeID = clientTradeID;
|
||
this.price = price;
|
||
this.timeInForce = timeInForce;
|
||
this.gtdTime = gtdTime;
|
||
this.triggerCondition = triggerCondition;
|
||
this.clientExtensions = clientExtensions;
|
||
|
||
if (this.timeInForce == null)
|
||
this.timeInForce = TimeInForce.GTC;
|
||
|
||
if (this.triggerCondition == null)
|
||
this.triggerCondition = OrderTriggerCondition.DEFAULT;
|
||
}
|
||
}
|