TakeProfitDetails¶
-
class
oandapyV20.contrib.requests.
TakeProfitDetails
(price, timeInForce='GTC', gtdTime=None, clientExtensions=None)¶ Bases:
oandapyV20.contrib.requests.onfill.OnFill
Representation of the specification for a TakeProfitOrder.
It is typically used to specify ‘take profit details’ for the ‘takeProfitOnFill’ parameter of an OrderRequest. This way one can create the Take Profit Order as a dependency when an order gets filled.
The other way to create a TakeProfitOrder is to create it afterwards on an existing trade. In that case you use TakeProfitOrderRequest on the trade.
-
__init__
(price, timeInForce='GTC', gtdTime=None, clientExtensions=None)¶ Instantiate TakeProfitDetails.
Parameters: - price (float or string (required)) – the price to trigger take profit order
- timeInForce (TimeInForce (required), default TimeInForce.GTC) – the time in force
- gtdTime (DateTime (optional)) – gtdTime is required in case timeInForce == TimeInForce.GTD
Example
>>> import json >>> from oandapyV20 import API >>> import oandapyV20.endpoints.orders as orders >>> from oandapyV20.contrib.requests import ( >>> MarketOrderRequest, TakeProfitDetails) >>> >>> accountID = "..." >>> client = API(access_token=...) >>> # at time of writing EUR_USD = 1.0740 >>> # let us take profit at 1.10, GoodTillCancel (default) >>> takeProfitOnFillOrder = TakeProfitDetails(price=1.10) >>> print(takeProfitOnFillOrder.data) { "timeInForce": "GTC", "price": "1.10000" } >>> ordr = MarketOrderRequest( >>> instrument="EUR_USD", >>> units=10000, >>> takeProfitOnFill=takeProfitOnFillOrder.data >>> ) >>> # or as shortcut ... >>> # takeProfitOnFill=TakeProfitDetails(price=1.10).data >>> print(json.dumps(ordr.data, indent=4)) { "order": { "timeInForce": "FOK", "instrument": "EUR_USD", "units": "10000", "positionFill": "DEFAULT", "type": "MARKET", "takeProfitOnFill": { "timeInForce": "GTC", "price": "1.10000" } } } >>> r = orders.OrderCreate(accountID, data=ordr.data) >>> rv = client.request(r) >>> ...
-