Which API should I use?

  • Use v20 REST API only if you have a v20 account
  • Use v1 REST API if your account id contains only digits (ie. 2534253) as it is a legacy account

Account Endpoints

Get accounts for a user

Get a list of accounts owned by the user

GET /v1/accounts

Example

$curl -X GET "https://api-fxtrade.oanda.com/v1/accounts

Response

Header

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 128

Body

{
  "accounts": [
      {
        "accountId" : 8954947,
        "accountName" : "Primary",
        "accountCurrency" : "USD",
        "marginRate" : 0.05
      },
      {
        "accountId" : 8954950,
        "accountName" : "SweetHome",
        "accountCurrency" : "CAD",
        "marginRate" : 0.02
      }
  ]
}

Get account information

GET /v1/accounts/:account_id

Example

$curl -X GET "https://api-fxtrade.oanda.com/v1/accounts/8954947"

Response

Header

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 269

Body

{
  "accountId" : 8954947,
  "accountName" : "Primary",
  "balance" : 100000,
  "unrealizedPl" : 0,
  "realizedPl" : 0,
  "marginUsed" : 0,
  "marginAvail" : 100000,
  "openTrades" : 0,
  "openOrders" : 0,
  "marginRate" : 0.05,
  "accountCurrency" : "USD"
}