Built into AlgoGP Pro
BrokerMarket dataForexCFDsIndices API key

OANDA API guide

OANDA is a regulated forex and CFD broker whose v20 REST API exposes the same account to code that its apps use. A free practice account behaves like a live one with simulated money, and the same API serves both orders and historical candles, so one token covers data and execution.

Last verified

Quick answer

OANDA’s v20 REST API trades forex (and CFDs outside the US) and serves candles with one bearer token. Practice accounts use api-fxpractice.oanda.com and live accounts api-fxtrade.oanda.com. Limits are 120 REST requests per second per IP, 20 active streams and 2 new connections per second; orders are sized in units, with the sign giving direction.

OANDA API at a glance

Pricing
Free API with an account
Availability
US, UK, EU, Canada, Australia, Japan, Singapore
Paper trading
Free demo (fxPractice) account
Integration type
REST + API key
In AlgoGP
Built in: broker and data adapter (Pro)
Practice host
https://api-fxpractice.oanda.com
Live host
https://api-fxtrade.oanda.com
Auth
Authorization: Bearer <personal access token>
Candles
GET /v3/instruments/EUR_USD/candles, up to 5,000 per request

Instruments and units

Instruments use an underscore: EUR_USD, USD_JPY, XAU_USD, and CFDs such as SPX500_USD outside the US. Orders are sized in units of the base currency, and the sign is the direction: +10000 buys 10,000 EUR, -10000 sells. AlgoGP’s adapter converts EUR/USD and its long/flat signals for you and rounds to whole units.

EndpointUse
GET /v3/accounts/{id}/summaryBalance, NAV, margin used
GET /v3/accounts/{id}/openPositionsLong and short units per instrument
POST /v3/accounts/{id}/ordersMarket, limit, stop and attached TP/SL orders
GET /v3/instruments/{instrument}/candlesBid, ask or mid candles from S5 to M

Historical candles

Request granularity (M1, M15, H1, H4, D, W…), price (M for mid, B bid, A ask) and either count or a from/to range. Each candle carries a complete flag: the last one is usually still forming and should not drive a decision. Mid candles are right for signals; bid/ask candles are what fills actually see.

Rate limits

  • 120 REST requests per second per IP address.
  • Up to 20 active streaming connections per IP; at most 2 new connections per second.
  • Up to 5,000 candles per candles request.

Regions, leverage and products

Which OANDA entity you open an account with depends on where you live, and that decides the products and leverage. US accounts trade spot forex (and a few metals) at regulated leverage caps and cannot trade CFDs; most other regions add index, commodity and bond CFDs.

Use OANDA in AlgoGP

Open a project, go to the APIs & keys tab and, under Platforms, pick OANDA as the market data source (market_data.py) and the broker (brokers.py). The choice is saved to config.json as a new strategy version:

{
  "platforms": {
    "data": "oanda",
    "broker": "oanda"
  }
}
In-app backtests always use AlgoGP’s normalized history so results stay comparable; this choice decides what backtest.py and live.py connect to when you run the exported code.
KeyWhat it is
OANDA_API_TOKENOANDA v20 personal access token (Tools → API in the OANDA Hub).
OANDA_ACCOUNT_IDThe v20 account id to trade, e.g. 101-001-1234567-001.
Names the generated code reads. Add values under Keys & secrets or in a local .env.
  • TRADING_MODE=paper (default): simulated fills on your machine; the broker is never contacted.
  • TRADING_MODE=sandbox: orders go to OANDA’s free demo (fxpractice) account.
  • TRADING_MODE=live: real orders, and only once LIVE_TRADING_ACKNOWLEDGED=yes is set.

New to OANDA? Follow the step-by-step OANDA API key guide.

OANDA API: frequently asked questions

Is the OANDA API free?

Yes. API access comes with any practice or live account; you pay spreads (and commission on some account types) on trades.

Does the same token work for practice and live?

No. Generate the token while logged into the account type you want; practice tokens only work against api-fxpractice.oanda.com.

Can I get historical forex data from OANDA?

Yes. The candles endpoint serves years of history at every granularity, up to 5,000 candles per request.

Build an OANDA trading bot in minutes

Describe the strategy in plain English, backtest it on years of data, then export Python that already talks to OANDA: paper, sandbox and live modes, keys handled for you.

  • Generated adapter for OANDA orders and balances
  • Backtests with costs, slippage and walk-forward checks
  • Paper first; live trading only after you opt in

Free plan, no card required. OANDA is included with Pro.

OANDA alternatives

Independent guide. AlgoGP is not affiliated with OANDA. Limits, prices and availability change; confirm them in the official documentation. Nothing here is investment advice.