Comprehensive account operations including listing accounts, retrieving account details and summaries, querying tradable instruments, configuring account settings, and polling for account changes.
All account operations are accessed via ctx.account where ctx is a Context instance.
Get a list of all Accounts authorized for the provided token.
/**
* Get list of all Accounts authorized for the token
* @param responseHandler - Callback receiving Response object
* Response body contains: { accounts: AccountProperties[] }
*/
list(responseHandler);Usage Example:
ctx.account.list(response => {
if (response.isSuccess()) {
const accounts = response.body.accounts;
accounts.forEach(acc => {
console.log(`Account ID: ${acc.id}, Tags: ${acc.tags.join(', ')}`);
});
}
});Get the full details for a single Account.
/**
* Get full Account details
* @param accountID - Account identifier
* @param responseHandler - Callback receiving Response object
* Response body contains: { account: Account, lastTransactionID: string }
*/
get(accountID, responseHandler);Usage Example:
ctx.account.get('001-001-1234567-001', response => {
if (response.isSuccess()) {
const account = response.body.account;
console.log(`Balance: ${account.balance} ${account.currency}`);
console.log(`Unrealized P/L: ${account.unrealizedPL}`);
console.log(`NAV: ${account.NAV}`);
console.log(`Margin Used: ${account.marginUsed}`);
console.log(`Margin Available: ${account.marginAvailable}`);
console.log(`Open Trades: ${account.openTradeCount}`);
console.log(`Open Positions: ${account.openPositionCount}`);
console.log(`Pending Orders: ${account.pendingOrderCount}`);
}
});Get a summary for a single Account.
/**
* Get Account summary (lighter version without trades, positions, orders arrays)
* @param accountID - Account identifier
* @param responseHandler - Callback receiving Response object
* Response body contains: { account: AccountSummary, lastTransactionID: string }
*/
summary(accountID, responseHandler);Usage Example:
ctx.account.summary('001-001-1234567-001', response => {
if (response.isSuccess()) {
const account = response.body.account;
console.log(`Balance: ${account.balance} ${account.currency}`);
console.log(`Unrealized P/L: ${account.unrealizedPL}`);
}
});Get the list of tradeable instruments for an Account.
/**
* Get tradable instruments for Account
* @param accountID - Account identifier
* @param queryParams - Query parameters object
* - instruments: string (comma-separated list of instrument names, optional)
* @param responseHandler - Callback receiving Response object
* Response body contains: { instruments: Instrument[] }
*/
instruments(accountID, queryParams, responseHandler);Usage Example:
// Get all tradable instruments
ctx.account.instruments('001-001-1234567-001', {}, response => {
if (response.isSuccess()) {
response.body.instruments.forEach(inst => {
console.log(`${inst.name}: ${inst.displayName}`);
console.log(` Type: ${inst.type}`);
console.log(` Margin Rate: ${inst.marginRate}`);
});
}
});
// Get specific instruments
ctx.account.instruments('001-001-1234567-001', {
instruments: 'EUR_USD,GBP_USD,USD_JPY'
}, response => {
if (response.isSuccess()) {
console.log('Requested instruments:', response.body.instruments);
}
});Configure an Account's settings.
/**
* Configure Account settings
* @param accountID - Account identifier
* @param bodyParams - Body parameters object
* - alias: string (account alias, optional)
* - marginRate: string (margin rate override, optional)
* @param responseHandler - Callback receiving Response object
* Response body contains: { clientConfigureTransaction: ClientConfigureTransaction, lastTransactionID: string }
*/
configure(accountID, bodyParams, responseHandler);Usage Example:
ctx.account.configure('001-001-1234567-001', {
alias: 'My Trading Account',
marginRate: '0.02'
}, response => {
if (response.isSuccess()) {
console.log('Account configured successfully');
console.log('Transaction ID:', response.body.lastTransactionID);
}
});Poll an Account for changes since a specified Transaction ID.
/**
* Poll Account for changes since transaction ID
* @param accountID - Account identifier
* @param queryParams - Query parameters object
* - sinceTransactionID: string (transaction ID to poll from, required)
* @param responseHandler - Callback receiving Response object
* Response body contains: {
* changes: AccountChanges,
* state: AccountChangesState,
* lastTransactionID: string
* }
*/
changes(accountID, queryParams, responseHandler);Usage Example:
ctx.account.changes('001-001-1234567-001', {
sinceTransactionID: '1234'
}, response => {
if (response.isSuccess()) {
const changes = response.body.changes;
const state = response.body.state;
console.log('Orders Created:', changes.ordersCreated.length);
console.log('Orders Filled:', changes.ordersFilled.length);
console.log('Trades Opened:', changes.tradesOpened.length);
console.log('Trades Closed:', changes.tradesClosed.length);
console.log('Transactions:', changes.transactions.length);
console.log('Current NAV:', state.NAV);
console.log('Current Unrealized P/L:', state.unrealizedPL);
}
});Full representation of an Account.
interface Account {
// Identification
id: string;
alias: string;
currency: string;
// Account creation
createdByUserID: string;
createdTime: string;
// Financial summary
balance: string;
pl: string;
resettablePL: string;
resettablePLTime: string;
financing: string;
commission: string;
guaranteedExecutionFees: string;
// Margin and risk
marginRate: string;
marginCallEnterTime?: string;
marginCallExtensionCount?: number;
lastMarginCallExtensionTime?: string;
// Guaranteed stop loss
guaranteedStopLossOrderMode: string;
// Position and order counts
openTradeCount: number;
openPositionCount: number;
pendingOrderCount: number;
hedgingEnabled: boolean;
// Timestamps
lastOrderFillTimestamp?: string;
lastTransactionID: string;
// Real-time financial state
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;
// Collections
trades: TradeSummary[];
positions: Position[];
orders: Order[];
}Summary representation of an Account (excludes trades, positions, orders arrays).
interface AccountSummary {
// Same properties as Account except:
// - No trades array
// - No positions array
// - No orders array
id: string;
alias: string;
currency: string;
createdByUserID: string;
createdTime: string;
balance: string;
pl: string;
resettablePL: string;
resettablePLTime: string;
financing: string;
commission: string;
guaranteedExecutionFees: string;
marginRate: string;
marginCallEnterTime?: string;
marginCallExtensionCount?: number;
lastMarginCallExtensionTime?: string;
guaranteedStopLossOrderMode: string;
openTradeCount: number;
openPositionCount: number;
pendingOrderCount: number;
hedgingEnabled: boolean;
lastOrderFillTimestamp?: string;
lastTransactionID: 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;
}Properties of an Account.
interface AccountProperties {
id: string;
mt4AccountID?: string;
tags: string[];
}Changes to an Account over a time period.
interface AccountChanges {
ordersCreated: Order[];
ordersCancelled: Order[];
ordersFilled: Order[];
ordersTriggered: Order[];
tradesOpened: TradeSummary[];
tradesReduced: TradeSummary[];
tradesClosed: TradeSummary[];
positions: Position[];
transactions: Transaction[];
}Price-dependent state of an Account.
interface AccountChangesState {
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[];
}Calculated price-dependent state of an Account.
interface CalculatedAccountState {
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;
}