StopLossDetails¶
-
class
oandapyV20.contrib.requests.
StopLossDetails
(price, timeInForce='GTC', gtdTime=None, clientExtensions=None)¶ Bases:
oandapyV20.contrib.requests.onfill.OnFill
Representation of the specification for a StopLossOrder.
It is typically used to specify ‘stop loss details’ for the ‘stopLossOnFill’ parameter of an OrderRequest. This way one can create the Stop Loss Order as a dependency when an order gets filled.
The other way to create a StopLossOrder is to create it afterwards on an existing trade. In that case you use StopLossOrderRequest on the trade.
-
__init__
(price, timeInForce='GTC', gtdTime=None, clientExtensions=None)¶ Instantiate StopLossDetails.
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
- clientExtensions (ClientExtensions (optional)) –
Example
>>> import json >>> from oandapyV20 import API >>> import oandapyV20.endpoints.orders as orders >>> from oandapyV20.contrib.requests import ( >>> MarketOrderRequest, StopLossDetails) >>> >>> accountID = "..." >>> client = API(access_token=...) >>> # at time of writing EUR_USD = 1.0740 >>> # let us take profit at 1.10, GoodTillCancel (default) >>> stopLossOnFill = StopLossDetails(price=1.06) >>> print(stopLossOnFill) { "timeInForce": "GTC", "price": "1.10000" } >>> ordr = MarketOrderRequest( >>> instrument="EUR_USD", >>> units=10000, >>> stopLossOnFill=stopLossOnFill.data >>> ) >>> # or as shortcut ... >>> # stopLossOnFill=StopLossDetails(price=1.06).data >>> print(json.dumps(ordr.data, indent=4)) >>> r = orders.OrderCreate(accountID, data=ordr.data) >>> rv = client.request(r) >>> ...
-