Open Positions

Lets get the open positions. It should show the total units LONG and SHORT per instrument and the tradeID's associated with the position.


In [1]:
import json
import oandapyV20
import oandapyV20.endpoints.positions as positions
from exampleauth import exampleauth

accountID, access_token = exampleauth.exampleAuth()
client = oandapyV20.API(access_token=access_token)

r = positions.OpenPositions(accountID=accountID)
rv = client.request(r)
print("Response: ", json.dumps(rv, indent=2))


Response:  {
  "positions": [
    {
      "pl": "-752.7628",
      "resettablePL": "-752.7628",
      "unrealizedPL": "-128.4516",
      "short": {
        "units": "0",
        "pl": "-101.7859",
        "resettablePL": "-101.7859",
        "unrealizedPL": "0.0000"
      },
      "instrument": "EUR_USD",
      "long": {
        "units": "50000",
        "pl": "-650.9769",
        "resettablePL": "-650.9769",
        "averagePrice": "1.05836",
        "unrealizedPL": "-128.4516",
        "tradeIDs": [
          "4224",
          "7558",
          "7562",
          "7572",
          "7579"
        ]
      }
    }
  ],
  "lastTransactionID": "7582"
}