or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

account.mdcore.mdindex.mdinstruments.mdorders.mdpositions.mdpricing.mdtrades.mdtransactions.mdusers.md
tile.json

tessl/maven-oanda--v20

Java bindings for the OANDA v20 REST API enabling programmatic access to forex trading, account management, market data, and transaction history

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/com.oanda.v20/v20@3.0.x

To install, run

npx @tessl/cli install tessl/maven-oanda--v20@3.0.0

index.mddocs/

OANDA v20 JavaScript SDK

JavaScript bindings for the OANDA v20 REST API. Callback-based SDK with zero external dependencies.

Package

  • Package: @oanda/v20
  • Installation: npm install @oanda/v20
  • License: MIT
  • Docs: http://developer.oanda.com/rest-live-v20/introduction

Quick Start

const { 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);
  }
});

Core Architecture

Context

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;
}

Response

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
}

Callback Pattern

All methods use callbacks:

ctx.module.method(params, (response) => {
  if (response.isSuccess()) {
    // Access response.body
  } else if (response.isClientError()) {
    // Handle 4xx errors
  }
});

Streaming Pattern

Streaming endpoints accept chunk and completion handlers:

ctx.module.stream(
  accountID,
  queryParams,
  (chunk) => {
    // Handle each chunk (JSON.parse if needed)
  },
  (response) => {
    // Handle completion/error
  }
);

API Modules

Account Management

Account details, balance, margin, instruments, configuration.

Account Management

Order Management

Create, list, modify, cancel orders. Market, limit, stop, take profit, stop loss, trailing stop.

Order Management

Trade Management

List, get, close trades. Set dependent orders (TP/SL).

Trade Management

Position Management

List, get, close positions by instrument.

Position Management

Transaction History

List, get, stream transactions. Pagination and filtering.

Transaction History

Market Pricing

Real-time prices, streaming, candlesticks, conversion factors.

Market Pricing

Instrument Data

Candlesticks, prices, order books, position books.

Instrument Data

User Information

User profile and external user data.

User Information

Core Infrastructure

Base classes and common patterns.

Core Infrastructure

Common Types

  • AccountID: String (e.g., "101-004-12345678-001")
  • OrderID: String
  • TradeID: String
  • TransactionID: String
  • InstrumentName: String (e.g., "EUR_USD", "GBP_JPY")
  • DateTime: ISO 8601 string
  • DecimalNumber: String (for precision)
  • AccountUnits: String
  • PriceValue: String

Response Body Patterns

// Single entity
{ account: {...}, lastTransactionID: "12345" }

// List
{ accounts: [...], lastTransactionID: "12345" }

// Transaction
{ orderCreateTransaction: {...}, orderFillTransaction: {...}, lastTransactionID: "12346" }

// Error
{ errorCode: "INVALID_UNITS", errorMessage: "..." }

Authentication

Bearer token authentication:

ctx.setToken('your-bearer-token');
// Automatically included in Authorization header

Environments

Practice: 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);