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

core.mddocs/

Core Infrastructure

Foundation classes for all API interactions.

Context Class

Main entry point for API operations.

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 module properties
  account: AccountAPI;
  order: OrderAPI;
  trade: TradeAPI;
  position: PositionAPI;
  transaction: TransactionAPI;
  pricing: PricingAPI;
  instrument: InstrumentAPI;
  user: UserAPI;
  primitives: PrimitivesAPI;
  pricing_common: PricingCommonAPI;
  site: SiteAPI;
}

Usage:

const { Context } = require('@oanda/v20');
const ctx = new Context('api-fxpractice.oanda.com', 443, true, 'MyApp');
ctx.setToken('token');
ctx.account.list(accountID, callback);

Response Class

HTTP response wrapper with status helpers.

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
}

Usage:

ctx.account.get(accountID, (response) => {
  if (response.isSuccess()) {
    const account = response.body.account;
  } else if (response.isClientError()) {
    console.error(response.body.errorMessage);
  }
});

Definition Base Class

Base class for all API entity classes.

class Definition {
  toJSON(): object;
  name(): string;
  summary(): string;
  title(): string;
  toString(): string;
  fields(): Field[];
}

Usage:

const trade = response.body.trade;
console.log(trade.name());      // "Trade 12345"
console.log(trade.summary());   // "1000 (1000) of EUR_USD @ 1.08500"
console.log(trade.toJSON());    // JSON representation

Property and Field Classes

class Property {
  constructor(name: string, displayName: string, description: string, typeClass: string, typeName: string);
}

class Field extends Property {
  constructor(property: Property, value: any);
}

Response Body Patterns

Single Entity

{
  account: { /* Account object */ },
  lastTransactionID: "12345"
}

List

{
  accounts: [ /* Array of Account objects */ ],
  lastTransactionID: "12345"
}

Transaction

{
  orderCreateTransaction: { /* Transaction object */ },
  orderFillTransaction: { /* Transaction object */ },
  relatedTransactionIDs: ["12345", "12346"],
  lastTransactionID: "12346"
}

Error

{
  errorCode: "INVALID_UNITS",
  errorMessage: "The units specified is invalid"
}

HTTP Methods

  • GET: Retrieve data
  • POST: Create resources
  • PUT: Update/replace resources
  • PATCH: Partial updates

Streaming

Streaming endpoints provide real-time data:

ctx.module.stream(
  accountID,
  queryParams,
  (chunk) => {
    const data = JSON.parse(chunk);
    if (data.type === 'PRICE') {
      // Handle price update
    } else if (data.type === 'HEARTBEAT') {
      // Keep-alive
    }
  },
  (response) => {
    if (response.isError()) {
      console.error('Stream error:', response.statusMessage);
    }
  }
);

Available streams:

  • ctx.pricing.stream() - Real-time prices
  • ctx.transaction.stream() - Real-time transactions

Authentication

Bearer token authentication:

ctx.setToken('your-bearer-token');
// Authorization: Bearer <token>

Headers automatically included:

Content-Type: application/json
OANDA-Agent: v20-javascript/3.0.25 (YourApplicationName)
Authorization: Bearer <token>

Error Handling

function handleResponse(response, successCallback) {
  if (response.isSuccess()) {
    successCallback(response.body);
  } else if (response.statusCode === '401') {
    console.error('Authentication failed');
  } else if (response.statusCode === '404') {
    console.error('Resource not found');
  } else if (response.statusCode === '400') {
    console.error('Bad request:', response.body.errorMessage);
  } else if (response.isClientError()) {
    console.error(`Client error ${response.statusCode}:`, response.body);
  } else if (response.isServerError()) {
    console.error(`Server error ${response.statusCode}:`, response.statusMessage);
  }
}

Primitive Data Classes

Instrument

class Instrument extends Definition {
  name: string;
  type: string;
  displayName: string;
  pipLocation: number;
  displayPrecision: number;
  tradeUnitsPrecision: number;
  minimumTradeSize: string;
  maximumTrailingStopDistance: string;
  minimumTrailingStopDistance: string;
  maximumPositionSize: string;
  maximumOrderUnits: string;
  marginRate: string;
  commission: InstrumentCommission;
}

InstrumentCommission

class InstrumentCommission extends Definition {
  commission: string;
  unitsTraded: string;
  minimumCommission: string;
}

GuaranteedStopLossOrderLevelRestriction

class GuaranteedStopLossOrderLevelRestriction extends Definition {
  volume: string;
  priceRange: string;
}

Node.js Requirements

  • Node.js 6.0+ (ES6 class support)
  • Built-in modules only: http, https
  • No external dependencies