Open Trades

The previously executed Market-Order resulted in a trade: LONG 10000 EUR_USD. This results also in a Position. The position will be 10000 units also unless there were other trades opened in the same instrument. In that case the last 10000 units will be added to it.

Example: get the open trades. The trade that was opened has the id 7562. It should be in the list of trades that we get by performing an OpenTrades request.


In [2]:
import json
import oandapyV20
import oandapyV20.endpoints.trades as trades
from exampleauth import exampleauth

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

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


Response:  {
  "lastTransactionID": "7582",
  "trades": [
    {
      "state": "OPEN",
      "financing": "0.0000",
      "stopLossOrder": {
        "state": "PENDING",
        "timeInForce": "GTC",
        "price": "1.05000",
        "triggerCondition": "TRIGGER_DEFAULT",
        "createTime": "2017-03-09T13:22:13.832587780Z",
        "id": "7581",
        "type": "STOP_LOSS",
        "tradeID": "7579"
      },
      "realizedPL": "0.0000",
      "price": "1.05563",
      "unrealizedPL": "-0.8526",
      "instrument": "EUR_USD",
      "initialUnits": "10000",
      "id": "7579",
      "openTime": "2017-03-09T13:22:13.832587780Z",
      "currentUnits": "10000"
    },
    {
      "state": "OPEN",
      "financing": "0.0000",
      "stopLossOrder": {
        "state": "PENDING",
        "timeInForce": "GTC",
        "price": "1.05000",
        "triggerCondition": "TRIGGER_DEFAULT",
        "createTime": "2017-03-09T11:45:48.928448770Z",
        "id": "7574",
        "type": "STOP_LOSS",
        "tradeID": "7572"
      },
      "realizedPL": "0.0000",
      "price": "1.05580",
      "unrealizedPL": "-2.4632",
      "instrument": "EUR_USD",
      "initialUnits": "10000",
      "id": "7572",
      "openTime": "2017-03-09T11:45:48.928448770Z",
      "currentUnits": "10000"
    },
    {
      "state": "OPEN",
      "financing": "-0.2693",
      "stopLossOrder": {
        "state": "PENDING",
        "timeInForce": "GTC",
        "price": "1.05000",
        "triggerCondition": "TRIGGER_DEFAULT",
        "createTime": "2017-03-07T09:18:51.563637768Z",
        "id": "7564",
        "type": "STOP_LOSS",
        "tradeID": "7562"
      },
      "realizedPL": "0.0000",
      "price": "1.05837",
      "unrealizedPL": "-26.8109",
      "instrument": "EUR_USD",
      "initialUnits": "10000",
      "id": "7562",
      "openTime": "2017-03-07T09:18:51.563637768Z",
      "currentUnits": "10000"
    },
    {
      "state": "OPEN",
      "financing": "-0.2706",
      "stopLossOrder": {
        "state": "PENDING",
        "timeInForce": "GTC",
        "price": "1.05000",
        "triggerCondition": "TRIGGER_DEFAULT",
        "createTime": "2017-03-07T09:08:04.219010730Z",
        "id": "7560",
        "type": "STOP_LOSS",
        "tradeID": "7558"
      },
      "realizedPL": "0.0000",
      "price": "1.05820",
      "unrealizedPL": "-25.2004",
      "instrument": "EUR_USD",
      "initialUnits": "10000",
      "id": "7558",
      "openTime": "2017-03-07T09:08:04.219010730Z",
      "currentUnits": "10000"
    },
    {
      "state": "OPEN",
      "financing": "-4.7102",
      "realizedPL": "0.0000",
      "price": "1.06381",
      "unrealizedPL": "-78.3485",
      "instrument": "EUR_USD",
      "initialUnits": "10000",
      "id": "4224",
      "openTime": "2017-02-10T21:50:02.670154087Z",
      "currentUnits": "10000"
    }
  ]
}