PositionClose¶
-
class
oandapyV20.endpoints.positions.
PositionClose
(accountID, instrument, data)¶ Bases:
oandapyV20.endpoints.positions.Positions
Closeout the open Position regarding instrument in an Account.
-
ENDPOINT
= 'v3/accounts/{accountID}/positions/{instrument}/close'¶
-
EXPECTED_STATUS
= 200¶
-
HEADERS
= {'Content-Type': 'application/json'}¶
-
METHOD
= 'PUT'¶
-
__init__
(accountID, instrument, data)¶ Instantiate a PositionClose request.
Parameters: - accountID (string (required)) – id of the account to perform the request on.
- instrument (string (required)) – instrument to close partially or fully.
- data (dict (required)) – closeout specification data to send, check developer.oanda.com for details.
Data body example:
{ "longUnits": "ALL" }
>>> import oandapyV20 >>> import oandapyV20.endpoints.positions as positions >>> accountID = ... >>> instrument = ... >>> client = oandapyV20.API(access_token=...) >>> data = { "longUnits": "ALL" }
>>> r = positions.PositionClose(accountID=accountID, >>> instrument=instrument, >>> data=data) >>> client.request(r) >>> print r.response
Output:
{ "longOrderCreateTransaction": { "longPositionCloseout": { "units": "ALL", "instrument": "EUR_USD" }, "batchID": "6390", "reason": "POSITION_CLOSEOUT", "id": "6390", "timeInForce": "FOK", "positionFill": "REDUCE_ONLY", "userID": "<USERID>", "instrument": "EUR_USD", "time": "2016-06-22T18:41:35.034041665Z", "units": "-251", "type": "MARKET_ORDER", "accountID": "<ACCOUNT>" }, "relatedTransactionIDs": [ "6390", "6391" ], "lastTransactionID": "6391", "longOrderFillTransaction": { "price": "1.13018", "batchID": "6390", "accountBalance": "43650.69807", "reason": "MARKET_ORDER_POSITION_CLOSEOUT", "tradesClosed": [ { "units": "-1", "financing": "0.00000", "realizedPL": "-0.00013", "tradeID": "6383" }, { "units": "-250", "financing": "0.00000", "realizedPL": "-0.03357", "tradeID": "6385" } ], "id": "6391", "orderID": "6390", "financing": "0.00000", "userID": "<USERID>", "instrument": "EUR_USD", "time": "2016-06-22T18:41:35.034041665Z", "units": "-251", "type": "ORDER_FILL", "pl": "-0.03370", "accountID": "<ACCOUNT>" } }
-