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

account.mddocs/

Account Management

Account operations: details, balance, margin, instruments, configuration.

API Methods

list

List all accounts authorized for the token.

list(responseHandler: (response: Response) => void): void;

Response: { accounts: AccountProperties[], lastTransactionID: string }

Example:

ctx.account.list((response) => {
  if (response.isSuccess()) {
    response.body.accounts.forEach(account => {
      console.log(account.id);
    });
  }
});

get

Get complete account details including trades, positions, orders.

get(accountID: string, responseHandler: (response: Response) => void): void;

Response: { account: Account, lastTransactionID: string }

Example:

ctx.account.get(accountID, (response) => {
  if (response.isSuccess()) {
    const account = response.body.account;
    console.log(account.balance, account.NAV, account.unrealizedPL);
  }
});

summary

Get account summary without full trade/position/order details.

summary(accountID: string, responseHandler: (response: Response) => void): void;

Response: { account: AccountSummary, lastTransactionID: string }

Example:

ctx.account.summary(accountID, (response) => {
  if (response.isSuccess()) {
    const summary = response.body.account;
    console.log(summary.balance, summary.NAV, summary.marginAvailable);
  }
});

instruments

Get tradeable instruments for the account.

instruments(
  accountID: string,
  queryParams: { instruments?: string },
  responseHandler: (response: Response) => void
): void;

Response: { instruments: Instrument[], lastTransactionID: string }

Example:

ctx.account.instruments(accountID, {}, (response) => {
  if (response.isSuccess()) {
    response.body.instruments.forEach(instrument => {
      console.log(instrument.name, instrument.marginRate);
    });
  }
});

// Filter specific instruments
ctx.account.instruments(accountID, { instruments: 'EUR_USD,GBP_USD' }, callback);

configure

Configure account settings.

configure(
  accountID: string,
  bodyParams: { alias?: string; marginRate?: string },
  responseHandler: (response: Response) => void
): void;

Response: { clientConfigureTransaction: ClientConfigureTransaction, lastTransactionID: string }

Example:

ctx.account.configure(accountID, { alias: 'My Account' }, (response) => {
  if (response.isSuccess()) {
    console.log('Configured:', response.body.clientConfigureTransaction.id);
  }
});

changes

Get account changes since a transaction ID.

changes(
  accountID: string,
  queryParams: { sinceTransactionID: string },
  responseHandler: (response: Response) => void
): void;

Response: { changes: AccountChanges, state: AccountChangesState, lastTransactionID: string }

Example:

ctx.account.changes(accountID, { sinceTransactionID: '1234' }, (response) => {
  if (response.isSuccess()) {
    const changes = response.body.changes;
    console.log('New orders:', changes.ordersCreated.length);
    console.log('New trades:', changes.tradesOpened.length);
  }
});

Data Classes

Account

Complete account details.

class Account extends Definition {
  id: string;
  alias?: string;
  currency: string;
  balance: string;
  createdByUserID: number;
  createdTime: string;
  guaranteedStopLossOrderMode: string;
  pl: string;
  resettablePL: string;
  resettablePLTime: string;
  financing: string;
  commission: string;
  guaranteedExecutionFees: string;
  marginRate?: string;
  marginCallEnterTime?: string;
  marginCallExtensionCount?: number;
  lastMarginCallExtensionTime?: string;
  openTradeCount: number;
  openPositionCount: number;
  pendingOrderCount: number;
  hedgingEnabled: boolean;
  lastOrderFillTimestamp?: string;
  unrealizedPL: string;
  NAV: string;
  marginUsed: string;
  marginAvailable: string;
  positionValue: string;
  marginCloseoutUnrealizedPL: string;
  marginCloseoutNAV: string;
  marginCloseoutMarginUsed: string;
  marginCloseoutPercent: string;
  marginCloseoutPositionValue: string;
  withdrawalLimit: string;
  marginCallMarginUsed: string;
  marginCallPercent: string;
  lastTransactionID: string;
  trades: TradeSummary[];
  positions: Position[];
  orders: Order[];
}

AccountSummary

Account summary without trades/positions/orders arrays.

class AccountSummary extends Definition {
  // Same properties as Account except trades, positions, orders are omitted
}

AccountProperties

Basic account identifiers.

class AccountProperties extends Definition {
  id: string;
  mt4AccountID?: number;
  tags: string[];
}

AccountChanges

Changes to account state.

class AccountChanges extends Definition {
  ordersCreated: Order[];
  ordersCancelled: Order[];
  ordersFilled: Order[];
  ordersTriggered: Order[];
  tradesOpened: TradeSummary[];
  tradesReduced: TradeSummary[];
  tradesClosed: TradeSummary[];
  positions: Position[];
  transactions: Transaction[];
}

AccountChangesState

Price-dependent account state.

class AccountChangesState extends Definition {
  unrealizedPL: string;
  NAV: string;
  marginUsed: string;
  marginAvailable: string;
  positionValue: string;
  marginCloseoutUnrealizedPL: string;
  marginCloseoutNAV: string;
  marginCloseoutMarginUsed: string;
  marginCloseoutPercent: string;
  marginCloseoutPositionValue: string;
  withdrawalLimit: string;
  marginCallMarginUsed: string;
  marginCallPercent: string;
  orders: DynamicOrderState[];
  trades: CalculatedTradeState[];
  positions: CalculatedPositionState[];
}

CalculatedAccountState

Real-time calculated account metrics.

class CalculatedAccountState extends Definition {
  // Same as AccountChangesState except orders, trades, positions arrays are omitted
}

Error Handling

ctx.account.get(accountID, (response) => {
  if (response.isSuccess()) {
    const account = response.body.account;
  } else if (response.statusCode === '401') {
    console.error('Authentication failed');
  } else if (response.statusCode === '404') {
    console.error('Account not found');
  } else if (response.isClientError()) {
    console.error('Client error:', response.body.errorMessage);
  }
});

Related Types

  • TradeSummary - from trade module
  • Position - from position module
  • Order - from order module
  • Transaction - from transaction module
  • DynamicOrderState - from order module
  • CalculatedTradeState - from trade module
  • CalculatedPositionState - from position module
  • Instrument - from primitives module
  • ClientConfigureTransaction - from transaction module