Java bindings for the OANDA v20 REST API enabling programmatic access to forex trading, account management, market data, and transaction history
npx @tessl/cli install tessl/maven-oanda--v20@3.0.0JavaScript bindings for the OANDA v20 REST API. Callback-based SDK with zero external dependencies.
@oanda/v20npm install @oanda/v20const { Context } = require('@oanda/v20');
// Initialize context
const ctx = new Context(
'api-fxpractice.oanda.com', // hostname
443, // port
true, // SSL
'MyApp' // application name (optional)
);
ctx.setToken('your-api-token');
// Get account summary
ctx.account.summary('101-004-12345678-001', (response) => {
if (response.isSuccess()) {
console.log(response.body.account.balance);
}
});Main entry point managing HTTP connections and API modules.
class Context {
constructor(hostname: string, port: number, ssl: boolean, application?: string);
setToken(token: string): void;
request(method: string, path: string, body: object, streamChunkHandler: function, responseHandler: function): void;
// API modules
account: AccountAPI;
order: OrderAPI;
trade: TradeAPI;
position: PositionAPI;
transaction: TransactionAPI;
pricing: PricingAPI;
instrument: InstrumentAPI;
user: UserAPI;
}All API methods return Response objects:
class Response {
method: string;
path: string;
statusCode: string;
statusMessage: string;
contentType: string;
rawBody: string;
body: object;
isSuccess(): boolean; // 2xx
isRedirection(): boolean; // 3xx
isClientError(): boolean; // 4xx
isServerError(): boolean; // 5xx
isError(): boolean; // 4xx or 5xx
}All methods use callbacks:
ctx.module.method(params, (response) => {
if (response.isSuccess()) {
// Access response.body
} else if (response.isClientError()) {
// Handle 4xx errors
}
});Streaming endpoints accept chunk and completion handlers:
ctx.module.stream(
accountID,
queryParams,
(chunk) => {
// Handle each chunk (JSON.parse if needed)
},
(response) => {
// Handle completion/error
}
);Account details, balance, margin, instruments, configuration.
Create, list, modify, cancel orders. Market, limit, stop, take profit, stop loss, trailing stop.
List, get, close trades. Set dependent orders (TP/SL).
List, get, close positions by instrument.
List, get, stream transactions. Pagination and filtering.
Real-time prices, streaming, candlesticks, conversion factors.
Candlesticks, prices, order books, position books.
User profile and external user data.
Base classes and common patterns.
// Single entity
{ account: {...}, lastTransactionID: "12345" }
// List
{ accounts: [...], lastTransactionID: "12345" }
// Transaction
{ orderCreateTransaction: {...}, orderFillTransaction: {...}, lastTransactionID: "12346" }
// Error
{ errorCode: "INVALID_UNITS", errorMessage: "..." }Bearer token authentication:
ctx.setToken('your-bearer-token');
// Automatically included in Authorization headerPractice: api-fxpractice.oanda.com:443
Live: api-fxtrade.oanda.com:443
const practiceCtx = new Context('api-fxpractice.oanda.com', 443, true);
const liveCtx = new Context('api-fxtrade.oanda.com', 443, true);