Files
ATS_Esper/src/main/java/ats/orders/StopOrderRequest.java

265 lines
11 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package ats.orders;
import com.oanda.v20.order.OrderTriggerCondition;
import org.joda.time.DateTime;
/**
* Create a new stop order request to send to the OANDA API.
*
* @see <a href="https://developer.oanda.com/rest-live-v20/order-df/#StopOrderRequest">OANDA API docs</a>
*/
public class StopOrderRequest extends OrderRequest {
/**
* Instrument to open the order on. Example: "EUR_USD"
*/
public String instrument;
/**
* The quantity requested to be filled by the order. A
* posititive number of units results in a long Order, and a
* negative number of units results in a short Order.
*/
public int units;
/**
* The price threshold specified for the order. The order will
* only be filled by a market price that is equal to or worse than
* this price.
*/
public String price;
/**
* The worst market price that may be used to fill this Stop
* Order. If the market gaps and crosses through both the price
* and the priceBound, the Stop Order will be cancelled instead of
* being filled.
*/
public String priceBound;
/**
* The time-in-force requested for the order. 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 how Positions in the Account are modified when
* the Order is filled.
*/
public OrderPositionFill positionFill;
/**
* 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 OANDAs proprietary or partner trading
* platforms, their transaction history or their account
* statements. OANDA platforms always assume that an Orders
* trigger condition is set to the default value when indicating
* the distance from an Orders 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 String top Loss Order for a long
* trade valid values are “DEFAULT” and “BID”, and for short
* trades “DEFAULT” and “ASK” are valid.
*/
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;
/**
* TakeProfitDetails specifies the details of a Take Profit Order
* to be created on behalf of a client. This may happen when an
* Order is filled that opens a Trade requiring a Take Profit, or
* when a Trades dependent Take Profit Order is modified directly
* through the Trade.
*/
public TakeProfitDetails takeProfitOnFill;
/**
* StopLossDetails specifies the details of a Stop Loss Order to
* be created on behalf of a client. This may happen when an Order
* is filled that opens a Trade requiring a Stop Loss, or when a
* Trades dependent Stop Loss Order is modified directly through
* the Trade.
*/
public StopLossDetails stopLossOnFill;
/**
* TrailingStopLossDetails specifies the details of a Trailing
* Stop Loss Order to be created on behalf of a client. This may
* happen when an Order is filled that opens a Trade requiring a
* Trailing Stop Loss, or when a Trades dependent Trailing Stop
* Loss Order is modified directly through the Trade.
*/
public TrailingStopLossDetails trailingStopLossOnFill;
/**
* Client Extensions to add to the Trade created when the Order is
* filled (if such a Trade is created). Do not set, modify, or
* delete tradeClientExtensions if your account is associated with
* MT4.
*/
public ClientExtensions tradeClientExtensions;
/**
* Create a new stop order request to send to the OANDA API.
*
* @param instrument Instrument to open the order on.
* Example: "EUR_USD"
*
* @param units The quantity requested to be filled by the
* Order. A posititive number of units results in a long Order,
* and a negative number of units results in a short Order.
*
* @param price The price threshold specified for the order. The
* order will only be filled by a market price that is equal to or
* worse than this price.
*/
public StopOrderRequest(String instrument, int units, String price)
{
this(instrument, units, price, null, null, null,
null, null, null, null, null, null, null);
}
/**
* Create a new stop order request to send to the OANDA API.
*
* @param instrument Instrument to open the order on.
* Example: "EUR_USD"
*
* @param units The quantity requested to be filled by the
* Order. A posititive number of units results in a long Order,
* and a negative number of units results in a short Order.
*
* @param price The price threshold specified for the Order. The
* Order will only be filled by a market price that is equal to or
* worse than this price.
*
* @param priceBound The worst market price that may be used to
* fill this Stop Order. If the market gaps and crosses through
* both the price and the priceBound, the Stop Order will be
* cancelled instead of being filled.
*
* @param timeInForce The time-in-force requested for the Order.
* The default is TimeInForce.GTC.
*
* @param gtdTime The date when the Order will be cancelled on if
* timeInForce is GTD.
*
* @param positionFill Specification of how Positions in the Account
* are modified when the Order is filled. The default is
* OrderPositionFill.DEFAULT.
*
* @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 OANDAs
* proprietary or partner trading platforms, their transaction
* history or their account statements. OANDA platforms always
* assume that an Orders trigger condition is set to the default
* value when indicating the distance from an Orders 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.
*
* @param takeProfitOnFill TakeProfitDetails specifies the details of
* a Take Profit Order to be created on behalf of a client. This may
* happen when an Order is filled that opens a Trade requiring a Take
* Profit, or when a Trades dependent Take Profit Order is modified
* directly through the Trade.
*
* @param stopLossOnFill StopLossDetails specifies the details of a
* Stop Loss Order to be created on behalf of a client. This may
* happen when an Order is filled that opens a Trade requiring a Stop
* Loss, or when a Trades dependent Stop Loss Order is modified
* directly through the Trade.
*
* @param trailingStopLossOnFill TrailingStopLossDetails specifies the
* details of a Trailing Stop Loss Order to be created on behalf of a
* client. This may happen when an Order is filled that opens a Trade
* requiring a Trailing Stop Loss, or when a Trades dependent
* Trailing Stop Loss Order is modified directly through the Trade.
*
* @param tradeClientExtensions Client Extensions to add to the Trade
* created when the Order is filled (if such a Trade is created). Do
* not set, modify, or delete tradeClientExtensions if your account is
* associated with MT4.
*/
public StopOrderRequest(String instrument,
int units,
String price,
String priceBound,
TimeInForce timeInForce,
DateTime gtdTime,
OrderPositionFill positionFill,
OrderTriggerCondition triggerCondition,
ClientExtensions clientExtensions,
TakeProfitDetails takeProfitOnFill,
StopLossDetails stopLossOnFill,
TrailingStopLossDetails trailingStopLossOnFill,
ClientExtensions tradeClientExtensions)
{
super(OrderType.STOP);
this.instrument = instrument;
this.units = units;
this.price = price;
this.priceBound = priceBound;
this.timeInForce = timeInForce;
this.gtdTime = gtdTime;
this.positionFill = positionFill;
this.triggerCondition = triggerCondition;
this.clientExtensions = clientExtensions;
this.takeProfitOnFill = takeProfitOnFill;
this.stopLossOnFill = stopLossOnFill;
this.trailingStopLossOnFill = trailingStopLossOnFill;
this.tradeClientExtensions = tradeClientExtensions;
if (this.timeInForce == null)
this.timeInForce = TimeInForce.GTC;
if (this.positionFill == null)
this.positionFill = OrderPositionFill.DEFAULT;
if (this.triggerCondition == null)
this.triggerCondition = OrderTriggerCondition.DEFAULT;
}
}