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.
| Endpoint | Use |
|---|---|
GET /v3/accounts/{id}/summary | Balance, NAV, margin used |
GET /v3/accounts/{id}/openPositions | Long and short units per instrument |
POST /v3/accounts/{id}/orders | Market, limit, stop and attached TP/SL orders |
GET /v3/instruments/{instrument}/candles | Bid, 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"
}
}backtest.py and live.py connect to when you run the exported code.| Key | What it is |
|---|---|
OANDA_API_TOKEN | OANDA v20 personal access token (Tools → API in the OANDA Hub). |
OANDA_ACCOUNT_ID | The v20 account id to trade, e.g. 101-001-1234567-001. |
.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 onceLIVE_TRADING_ACKNOWLEDGED=yesis 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
- IG API GuideRegulated CFD, spread-betting and FX broker with a REST trading API, Lightstreamer streaming and a demo account.
- Saxo OpenAPI GuideThe API behind SaxoTraderGO: multi-asset trading in stocks, ETFs, options, futures, FX and CFDs, with a simulation environment.
- cTrader Open API GuideSpotware’s API for cTrader brokers: FX and CFD trading and data over TCP or WebSocket, JSON or Protobuf, with OAuth.
- Interactive Brokers API GuideThe broadest multi-asset broker API: stocks, options, futures, FX and bonds on 150+ markets, through TWS or IB Gateway.
Independent guide. AlgoGP is not affiliated with OANDA. Limits, prices and availability change; confirm them in the official documentation. Nothing here is investment advice.