TradeClose¶
-
class
oandapyV20.endpoints.trades.
TradeClose
(accountID, tradeID, data=None)¶ Bases:
oandapyV20.endpoints.trades.Trades
TradeClose.
Close (partially or fully) a specific open Trade in an Account.
-
ENDPOINT
= 'v3/accounts/{accountID}/trades/{tradeID}/close'¶
-
EXPECTED_STATUS
= 200¶
-
HEADERS
= {'Content-Type': 'application/json'}¶
-
METHOD
= 'PUT'¶
-
__init__
(accountID, tradeID, data=None)¶ Instantiate a TradeClose request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- tradeID (string (required)) – id of the trade to close.
- data (dict (optional)) – data to send, use this to close a trade partially. Check developer.oanda.com for details.
Data body example:
{ "units": 100 }
>>> import oandapyV20 >>> import oandapyV20.endpoints.trades as trades >>> client = oandapyV20.API(access_token=...) >>> data = { "units": 100 }
>>> r = trades.TradeClose(accountID=..., data=data) >>> client.request(r) >>> print r.response
Output:
{ "orderFillTransaction": { "price": "1.09289", "batchID": "2316", "accountBalance": "33848.1208", "reason": "MARKET_ORDER_TRADE_CLOSE", "tradesClosed": [ { "units": "-100", "financing": "0.0000", "realizedPL": "-0.1455", "tradeID": "2313" } ], "id": "2317", "orderID": "2316", "financing": "0.0000", "userID": 1435156, "instrument": "EUR_USD", "time": "2016-10-28T15:11:58.023004583Z", "units": "-100", "type": "ORDER_FILL", "pl": "-0.1455", "accountID": "101-004-1435156-001" }, "orderCreateTransaction": { "timeInForce": "FOK", "reason": "TRADE_CLOSE", "tradeClose": { "units": "100", "tradeID": "2313" }, "id": "2316", "batchID": "2316", "positionFill": "REDUCE_ONLY", "userID": 1435156, "instrument": "EUR_USD", "time": "2016-10-28T15:11:58.023004583Z", "units": "-100", "type": "MARKET_ORDER", "accountID": "101-004-1435156-001" }, "lastTransactionID": "2317", "relatedTransactionIDs": [ "2316", "2317" ] }
-