Account endpoints

Example: fetch account information

A simple example to retrieve the accounts belonging to a token:


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

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

r = accounts.AccountList()
response = client.request(r)
print(json.dumps(response, indent=2))


{
  "accounts": [
    {
      "tags": [],
      "id": "101-004-1435156-002"
    },
    {
      "tags": [],
      "id": "101-004-1435156-001"
    }
  ]
}

Request details

Lets get some details from the request itself after the client performed the request:


In [2]:
print("API-path: " , r)
print("METHOD: ", r.method)
print("Response status: ", r.status_code)
print("The account id's: ", [acc.get('id') for acc in r.response.get('accounts')])


API-path:  v3/accounts
METHOD:  GET
Response status:  200
The account id's:  ['101-004-1435156-002', '101-004-1435156-001']