Account operations: details, balance, margin, instruments, configuration.
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 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);
}
});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);
}
});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 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);
}
});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);
}
});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[];
}Account summary without trades/positions/orders arrays.
class AccountSummary extends Definition {
// Same properties as Account except trades, positions, orders are omitted
}Basic account identifiers.
class AccountProperties extends Definition {
id: string;
mt4AccountID?: number;
tags: string[];
}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[];
}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[];
}Real-time calculated account metrics.
class CalculatedAccountState extends Definition {
// Same as AccountChangesState except orders, trades, positions arrays are omitted
}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);
}
});