TakeProfitOrderRequest

class oandapyV20.contrib.requests.TakeProfitOrderRequest(tradeID, price, clientTradeID=None, timeInForce='GTC', gtdTime=None, clientExtensions=None)

Bases: oandapyV20.contrib.requests.baserequest.BaseRequest

create a TakeProfit OrderRequest.

TakeProfitOrderRequest is used to build the body for a TakeProfitOrder. The body can be used to pass to the OrderCreate endpoint.

__init__(tradeID, price, clientTradeID=None, timeInForce='GTC', gtdTime=None, clientExtensions=None)

Instantiate a TakeProfitOrderRequest.

Parameters:
  • tradeID (string (required)) – the tradeID of an existing trade
  • price (float (required)) – the price indicating the target price to close the order.

Example

>>> import json
>>> from oandapyV20 import API
>>> import oandapyV20.endpoints.orders as orders
>>> from oandapyV20.contrib.requests import TakeProfitOrderRequest
>>>
>>> accountID = "..."
>>> client = API(access_token=...)
>>> ordr = TakeProfitOrderRequest(tradeID="1234",
>>>                               price=1.22)
>>> print(json.dumps(ordr.data, indent=4))
{
    "order": {
        "timeInForce": "GTC",
        "price": "1.22000",
        "type": "TAKE_PROFIT",
        "tradeID": "1234"
    }
}
>>> r = orders.OrderCreate(accountID, data=ordr.data)
>>> rv = client.request(r)
>>> ...
data

data property.

return the JSON order body