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

Transaction Endpoints

Get transaction history

GET /v1/accounts/:account_id/transactions

Input Query Parameters

maxId: Optional The first transaction to get. The server will return transactions with id less than or equal to this, in descending order.

minId: Optional The last transaction to get. The server will return transactions with id greater or equal to this, in descending order.

count: Optional The maximum number of transactions to return. The maximum value that can be specified is 500. By default, if count is not specified, a maximum of 50 transactions will be fetched. Note: Transactions requests with the count parameter specified is rate limited to 1 per every 60 seconds.

instrument: Optional Retrieve transactions for a specific instrument only. Default: all.

ids: Optional An URL encoded comma (%2C) separated list of transaction ids to retrieve. Maximum number of ids: 50. No other parameter may be specified with the ids parameter.

Response Parameters

Transactions returned may be of different types describing an event that happened to an account. Transaction of each type contains only relevant sub-set of fields. The following fields are the most common:

id: The transaction ID.

accountId: The account ID of the user.

time: Time in a valid datetime format.

type: The possible types are:

MARKET_ORDER_CREATE , STOP_ORDER_CREATE, LIMIT_ORDER_CREATE, MARKET_IF_TOUCHED_ORDER_CREATE, ORDER_UPDATE, ORDER_CANCEL, ORDER_FILLED, TRADE_UPDATE, TRADE_CLOSE, MIGRATE_TRADE_OPEN, MIGRATE_TRADE_CLOSE, STOP_LOSS_FILLED, TAKE_PROFIT_FILLED, TRAILING_STOP_FILLED, MARGIN_CALL_ENTER, MARGIN_CALL_EXIT, MARGIN_CLOSEOUT, SET_MARGIN_RATE, TRANSFER_FUNDS, DAILY_INTEREST, FEE

instrument: The name of the instrument.

side: The direction of the action performed on the account, possible values are: buy, sell

units: The amount of units involved.

price: The execution or requested price.

lowerBound: The minimum execution price.

upperBound: The maximum execution price.

takeProfitPrice: The price of the take profit.

stopLossPrice: The price of the stop loss.

trailingStopLossDistance: The distance of the trailing stop in pips, up to one decimal place.

pl: The profit and loss value.

interest: The interest accrued.

accountBalance: The balance on the account after the event.

Example

$curl -X GET "https://api-fxtrade.oanda.com/v1/accounts/12345/transactions?instrument=EUR_USD&count=1"

Response

Header

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 196
X-Result-Count: 50

Body

{
  "transactions" : [
    {
      "id" : 175427739,
      "accountId" : 6531071,
      "time" : "2014-02-12T21:16:46Z",
      "type" : "ORDER_CANCEL",
      "orderId" : 175427728,
      "reason" : "CLIENT_REQUEST"
    }
  ]
}

Get information for a transaction

GET /v1/accounts/:account_id/transactions/:transaction_id

Example

curl -X GET "https://api-fxtrade.oanda.com/v1/accounts/12345/transactions/1170980"

Response

Header

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

Body

{
  "id" : 1170980,
  "accountId" : 12345,
  "time" : "2014-02-12T20:02:45Z",
  "type" : "TRADE_CLOSE",
  "instrument" : "EUR_USD",
  "units" : 1000,
  "side" : "sell",
  "price" : 1.35921,
  "pl" : 1.93,
  "interest" : 0,
  "accountBalance" : 1000026.0723,
  "tradeId" : 175427703 //Closed trade id
}

Get full account history

Submit a request for a full transaction history of a given account. A successfully accepted submission results in a response containing a URL in the Location header to a file that will be available once the request is served. Response for the URL will be HTTP 404 until the file is ready. Once served the URL will be valid for a certain amount of time.

GET /v1/accounts/:account_id/alltransactions

Example

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

Response

Header

HTTP/1.1 202 Accepted
Content-Type: application/json
Content-Length: 0
Location: https://fxtrade.oanda.com/53e58d3509cef65f33998c879dcccbd9.json.zip

Pagination

Transactions can be paginated with the count and maxId parameters. At most, a maximum of 50 transactions can be returned in one query. If more transactions exist than specified by the given or default count, then another request with the next smallest possible maxId should be made.

For example, if the smallest transaction id in a response was 10000001, then another request with maxId=10000000 should be made.

Transaction types and a sub-set of corresponding parameters

MARKET_ORDER_CREATE

A transaction of this type is created when a user has successfully traded a specified number of units of an instrument at the current market price.

Required Fields: id, accountId, time, type, instrument, side, units, price, pl, interest, accountBalance

Optional Fields: lowerBound, upperBound, takeProfitPrice, stopLossPrice, trailingStopLossDistance

Trade information: Transaction of a MARKET_ORDER_CREATE type also contains information about associated trade

tradeOpened: This object is appended to the json response if a new trade has been created. Trade related fields are: id, units.

tradeReduced: This object is appended to the json response if a trade has been closed or reduced. Trade related fields are: id, units, pl, interest.

STOP_ORDER_CREATE

A transaction of this type is created when a user has successfully placed a Stop order on his/her account. A Stop order is an order which buys or sells a specified number of units of an instrument when the market price for that instrument first becomes equal to or worse than the price threshold specified.

Required Fields: id, accountId, time, type, instrument, side, units, price, expiry, reason (CLIENT_REQUEST, MIGRATION)

Optional Fields: lowerBound, upperBound, takeProfitPrice, stopLossPrice, trailingStopLossDistance

LIMIT_ORDER_CREATE

A transaction of this type is created when a user has successfully placed a Limit order on his/her account. A Limit order is an order which buys or sells a specified number of units of an instrument when the market price for that instrument first becomes equal to or better than the price threshold specified.

Required Fields: id, accountId, time, type, instrument, side, units, price, expiry, reason (CLIENT_REQUEST, MIGRATION)

Optional Fields: lowerBound, upperBound, takeProfitPrice, stopLossPrice, trailingStopLossDistance

MARKET_IF_TOUCHED_ORDER_CREATE

A transaction of this type is created when a user has successfully placed a MarketIfTouched order on his/her account. A MarketIfTouched order is an order which buys or sells a specified number of units of an instrument when the market price for that instrument first touches or crosses the price threshold specified. This order replaces what is historically known as the “OANDA Limit Order”.

Required Fields: id, accountId, time, type, instrument, side, units, price, expiry, reason (CLIENT_REQUEST, MIGRATION)

Optional Fields: lowerBound, upperBound, takeProfitPrice, stopLossPrice, trailingStopLossDistance

ORDER_UPDATE

A transaction of this type is created when a user has successfully updated any of the LimitOrder, StopOrder, MarketIfTouched orders on his/her account.

Required Fields: id, accountId, time, type, instrument, units, price, orderId, reason (REPLACES_ORDER)

Optional Fields: lowerBound, upperBound, takeProfitPrice, stopLossPrice, trailingStopLossDistance

ORDER_CANCEL

A transaction of this type is created when an order is being closed due to one of the reasons: CLIENT_REQUEST, TIME_IN_FORCE_EXPIRED, ORDER_FILLED, MIGRATION. Order fill may result in a failure due to the following reasons: INSUFFICIENT_MARGIN, BOUNDS_VIOLATION, UNITS_VIOLATION, STOP_LOSS_VIOLATION, TAKE_PROFIT_VIOLATION, TRAILING_STOP_VIOLATION, MARKET_HALTED, ACCOUNT_NON_TRADABLE, NO_NEW_POSITION_ALLOWED, INSUFFICIENT_LIQUIDITY.

Required Fields: id, accountId, time, type, orderId, reason

ORDER_FILLED

A transaction of this type is created when an order has been filled.

Required Fields: id, accountId, time, type, instrument, units, side, price, pl, interest, accountBalance, orderId

Optional Fields: lowerBound, upperBound, takeProfitPrice, stopLossPrice, trailingStopLossDistance

Trade information: Transaction of an ORDER_FILLED type also contains information about an associated trade.

tradeOpened: This object is appended to the json response if a new trade has been created. Trade related fields are: id, units

tradeReduced: This object is appended to the json response if a trade has been closed or reduced. Trade related fields are: id, units, pl, interest

TRADE_UPDATE

A transaction of this type is created when a user has successfully updated a trade.

Required Fields: id, accountId, time, type, instrument, units, side, tradeId

Optional Fields: takeProfitPrice, stopLossPrice, trailingStopLossDistance

TRADE_CLOSE

A transaction of this type is created when a user has successfully closed a trade.

Required Fields: id, accountId, time, type, instrument, units, side, price, pl, interest, accountBalance, tradeId

MIGRATE_TRADE_CLOSE

A transaction of this type is created when a trade has been closed due to user migration to another division.

Required Fields: id, accountId, time, type, instrument, units, side, price, pl, interest, accountBalance, tradeId

MIGRATE_TRADE_OPEN

A transaction of this type is created when a trade is reopened on the account if the user migrated to another division.

Required Fields: id, accountId, time, type, instrument, side, units, price

Optional Fields: takeProfitPrice, stopLossPrice, trailingStopLossDistance

Trade information: Transaction of a MIGRATE_TRADE_OPEN type also contains information about associated trade

tradeOpened: This object is appended to the json response. Trade related fields are: id, units.

TAKE_PROFIT_FILLED

A transaction of this type is created when a Take Profit order has been filled on user’s account.

Required Fields: id, accountId, time, type, tradeId, instrument, units, side, price, pl, interest, accountBalance

STOP_LOSS_FILLED

A transaction of this type is created when a Stop Loss order has been filled on user’s account.

Required Fields: id, accountId, time, type, tradeId, instrument, units, side, price, pl, interest, accountBalance

TRAILING_STOP_FILLED

A transaction of this type is created when a Trailing Stop Loss order has been filled on user’s account.

Required Fields: id, accountId, time, type, tradeId, instrument, units, side, price, pl, interest, accountBalance

MARGIN_CALL_ENTER

A transaction of this type is created administratively to mark user’s account as being in a margin call.

Required Fields: id, accountId, time, type

MARGIN_CALL_EXIT

A transaction of this type is created administratively to mark user’s account exiting margin call state.

Required Fields: id, accountId, time, type

MARGIN_CLOSEOUT

A transaction of this type is created automatically by the system when the margin closeout value in user’s account declines to half or less than half of the margin used. A MARGIN_CLOSEOUT represents the closing of all open trades in user’s account.

Required Fields: id, accountId, time, type, instrument, units, side, price, pl, interest, accountBalance, tradeId

SET_MARGIN_RATE

A transaction of this type is created whenever user modifies margin rate for the account.

Required Fields: id, accountId, time, type, marginRate

TRANSFER_FUNDS

A transaction of this type is created whenever user successfully deposited or withdrew funds from the account. Amount specified is positive in case of deposit and negative in case of withdrawal.

Required Fields: id, accountId, time, type, amount, accountBalance, reason (CLIENT_REQUEST, ADJUSTMENT, MIGRATION)

DAILY_INTEREST

A transaction of this type is created automatically by the system to pay/collect the daily position and balance interest for an account. It is generated every day at 4pm America/New_York for accounts which have had a balance or open position during the previous day. The transaction itself is not guaranteed to be created exactly at 4pm each day, however the interest paid/collected is based only on the positions and balance that existed up to 4pm of the previous day.

Required Fields: id, accountId, time, type, instrument, interest, accountBalance

FEE

A transaction of this type is created automatically by the system to collect a fee if applicable.

Required Fields: id, accountId, time, type, amount, accountBalance, reason(FUNDS, CURRENSEE_MONTHLY, CURRENSEE_PERFORMANCE, SDR_REPORTING)

Example - MARKET_ORDER_CREATE

{
  "id" : 176403879,
  "accountId" : 6765103,
  "time" : "2014-04-07T18:31:05Z",
  "type" : "MARKET_ORDER_CREATE",
  "instrument" : "EUR_USD",
  "units" : 2,
  "side" : "buy",
  "price" : 1.25325,
  "pl" : 0,
  "interest" : 0,
  "accountBalance" : 100000,
  "tradeOpened" : {
    "id" : 176403879,
    "units" : 2
  }
}

Example - STOP_ORDER_CREATE

{
  "id" : 176403886,
  "accountId" : 6765103,
  "time" : "2014-04-07T19:20:05Z",
  "type" : "STOP_ORDER_CREATE",
  "instrument" : "EUR_USD",
  "units" : 2,
  "side" : "buy",
  "price" : 1,
  "expiry" : 1398902400,
  "reason" : "CLIENT_REQUEST"
}

Example - LIMIT_ORDER_CREATE

{
  "id" : 176403880,
  "accountId" : 6765103,
  "time" : "2014-04-07T18:34:32Z",
  "type" : "LIMIT_ORDER_CREATE",
  "instrument" : "EUR_USD",
  "units" : 2,
  "side" : "buy",
  "price" : 1,
  "expiry" : 1398902400,
  "reason" : "CLIENT_REQUEST"
}

Example - MARKET_IF_TOUCHED_ORDER_CREATE

{
  "id" : 176403882,
  "accountId" : 6765103,
  "time" : "2014-04-07T18:40:42Z",
  "type" : "MARKET_IF_TOUCHED_ORDER_CREATE",
  "instrument" : "EUR_USD",
  "units" : 2,
  "side" : "buy",
  "price" : 1,
  "expiry" : 1398902400,
  "reason" : "CLIENT_REQUEST"
}

Example - ORDER_UPDATE

{
  "id" : 176403883,
  "accountId" : 6765103,
  "time" : "2014-04-07T19:07:13Z",
  "type" : "ORDER_UPDATE",
  "instrument" : "EUR_USD",
  "units" : 3,
  "price" : 1,
  "expiry" : 1398902400,
  "orderId" : 176403880,
  "reason" : "REPLACES_ORDER"
}

Example - ORDER_CANCEL

{
  "id" : 176403881,
  "accountId" : 6765103,
  "time" : "2014-04-07T18:37:27Z",
  "type" : "ORDER_CANCEL",
  "orderId" : 176403880,
  "reason" : "CLIENT_REQUEST"
}

Example - ORDER_FILLED

{
  "id" : 175685908,
  "accountId" : 2610411,
  "time" : "2014-04-14T20:32:34Z",
  "type" : "ORDER_FILLED",
  "instrument" : "EUR_USD",
  "units" : 2,
  "side" : "buy",
  "price" : 1.3821,
  "pl" : 0,
  "interest" : 0,
  "accountBalance" : 100000,
  "orderId" : 175685907,
  "tradeOpened" : {
          "id" : 175685908,
          "units" : 2
  }
}

Example - TRADE_UPDATE

{
  "id" : 176403884,
  "accountId" : 6765103,
  "time" : "2014-04-07T19:09:38Z",
  "type" : "TRADE_UPDATE",
  "instrument" : "EUR_USD",
  "units" : 2,
  "side" : "",
  "stopLossPrice" : 1.1,
  "tradeId" : 176403879
}

Example - TRADE_CLOSE

{
  "id" : 176403885,
  "accountId" : 6765103,
  "time" : "2014-04-07T19:11:14Z",
  "type" : "TRADE_CLOSE",
  "instrument" : "EUR_USD",
  "units" : 2,
  "side" : "sell",
  "price" : 1.25918,
  "pl" : 0.0119,
  "interest" : 0,
  "accountBalance" : 100000.0119,
  "tradeId" : 176403879
}

Example - MIGRATE_TRADE_CLOSE

{
  "id" : 176403885,
  "accountId" : 6765103,
  "time" : "2014-04-07T19:11:14Z",
  "type" : "MIGRATE_TRADE_CLOSE",
  "instrument" : "EUR_USD",
  "units" : 2,
  "side" : "sell",
  "price" : 1.25918,
  "pl" : 0.0119,
  "interest" : 0,
  "accountBalance" : 100000.0119,
  "tradeId" : 176403879
}

Example - MIGRATE_TRADE_OPEN

{
  "id" : 175685908,
  "accountId" : 2610411,
  "time" : "2014-04-14T20:32:34Z",
  "type" : "MIGRATE_TRADE_OPEN",
  "instrument" : "EUR_USD",
  "units" : 2,
  "side" : "buy",
  "price" : 1.3821,
  "tradeOpened" : {
          "id" : 175685908,
          "units" : 2
  }
}

Example - TAKE_PROFIT_FILLED

{
  "id" : 175685954,
  "accountId" : 1491998,
  "time" : "2014-04-15T14:12:47Z",
  "type" : "TAKE_PROFIT_FILLED",
  "units" : 10,
  "tradeId" : 175685930,
  "instrument" : "EUR_USD",
  "side" : "sell",
  "price" : 1.38231,
  "pl" : 0.0001,
  "interest" : 0,
  "accountBalance" : 100000.0001
}

Example - STOP_LOSS_FILLED

{
  "id" : 175685918,
  "accountId" : 1403479,
  "time" : "2014-04-14T20:41:41Z",
  "type" : "STOP_LOSS_FILLED",
  "units" : 10,
  "tradeId" : 175685917,
  "instrument" : "EUR_USD",
  "side" : "sell",
  "price" : 1.3821,
  "pl" : -0.0003,
  "interest" : 0,
  "accountBalance" : 99999.9997
}

Example - TRAILING_STOP_FILLED

{
  "id" : 175739353,
  "accountId" : 1491998,
  "time" : "2014-04-15T15:21:21Z",
  "type" : "TRAILING_STOP_FILLED",
  "units" : 10,
  "tradeId" : 175739352,
  "instrument" : "EUR_USD",
  "side" : "sell",
  "price" : 1.38137,
  "pl" : -0.0009,
  "interest" : 0,
  "accountBalance" : 99999.9992
}

Example - MARGIN_CALL_ENTER

{
  "id" : 175739360,
  "accountId" : 1491998,
  "time" : "2014-04-15T15:21:21Z",
  "type" : "MARGIN_CALL_ENTER"
}

Example - MARGIN_CALL_EXIT

{
  "id" : 175739360,
  "accountId" : 1491998,
  "time" : "2014-04-15T15:21:21Z",
  "type" : "MARGIN_CALL_EXIT"
}

Example - MARGIN_CLOSEOUT

{
  "id" : 176403889,
  "accountId" : 6765103,
  "time" : "2014-04-07T19:11:14Z",
  "type" : "MARGIN_CLOSEOUT",
  "instrument" : "EUR_USD",
  "units" : 2,
  "side" : "sell",
  "price" : 1.25918,
  "pl" : 0.0119,
  "interest" : 0,
  "accountBalance" : 100000.0119,
  "tradeId" : 176403879
}

Example - SET_MARGIN_RATE

{
  "id" : 175739360,
  "accountId" : 1491998,
  "time" : "2014-04-15T15:21:21Z",
  "type" : "SET_MARGIN_RATE",
  "rate" : 0.02
}

Example - TRANSFER_FUNDS

{
  "id" : 176403878,
  "accountId" : 6765103,
  "time" : "2014-04-07T18:29:25Z",
  "type" : "TRANSFER_FUNDS",
  "amount" : 100000,
  "accountBalance" : 100000,
  "reason" : "CLIENT_REQUEST"
}

Example - DAILY_INTEREST

{
  "id" : 175739363,
  "accountId" : 1491998,
  "time" : "2014-04-15T15:21:21Z",
  "type" : "DAILY_INTEREST",
  "instrument" : "EUR_USD",
  "interest" : 10.0414,
  "accountBalance" : 99999.9992
}

Example - FEE

{
  "id" : 175739369,
  "accountId" : 1491998,
  "time" : "2014-04-15T15:21:21Z",
  "type" : "FEE",
  "amount" : -10.0414,
  "accountBalance" : 99999.9992,
  "reason" : "FUNDS"
}