Skip to content

Accounts API

Account information retrieval operations.

Access via client.accounts.

AccountsAPI

AccountsAPI

Bases: BaseAPI

Account information operations.

Provides methods to discover the accounts an access token covers and to
retrieve account/trader details.

Example
account = await client.accounts.get_trader(account_id)
print(f"Balance: {account.get_balance()}")
print(f"Leverage: {account.get_leverage()}")

get_trader(account_id, timeout=None)

Get full account/trader information.

Parameters:

Name Type Description Default
account_id int

The cTID trader account ID.

required
timeout float | None

Request timeout (uses default if None).

None

Returns:

Type Description
Account

Full Account details including balance, leverage, etc.

Raises:

Type Description
APIError

If request fails.

CTraderConnectionTimeoutError

If request times out.

list_by_token(access_token, timeout=None)

List the trading accounts an access token covers.

Lists them without authenticating any of them, so a caller can discover
what is available, or let a user pick.

Parameters:

Name Type Description Default
access_token str

OAuth access token.

required
timeout float | None

Request timeout (uses default if None).

None

Returns:

Type Description
list[AccountSummary]

List of account summaries (lightweight account info).

Raises:

Type Description
TokenExpiredError

If the server rejects the access token.

APIError

If the request fails for any other reason.

CTraderConnectionTimeoutError

If request times out.

resolve_account_id(access_token, trader_login, timeout=None)

Resolve a trader login to its cTID trader account ID.

Parameters:

Name Type Description Default
access_token str

OAuth access token.

required
trader_login int

The trader login number (visible in cTrader app).

required
timeout float | None

Request timeout (uses default if None).

None

Returns:

Type Description
int

The cTID trader account ID (used for API calls).

Raises:

Type Description
AccountNotFoundError

If no account matches the trader login.

TokenExpiredError

If the server rejects the access token.

APIError

If the request fails.

CTraderConnectionTimeoutError

If request times out.

Usage Examples

Get Account Details

account = await client.accounts.get_trader(account_id)

print(f"Balance: {account.balance}")
print(f"Leverage: {account.get_leverage()}")
print(f"Account type: {account.account_type}")
print(f"Broker name: {account.broker_name}")

Account Discovery

The accounts an access token covers can be listed without authenticating any of
them:

# Get all accounts associated with a token
for acc in await client.accounts.list_by_token(access_token):
    print(f"Login: {acc.trader_login}, Account ID: {acc.account_id}")
    print(f"  Live: {acc.is_live}, Broker: {acc.broker_name}")

# Or resolve a single login straight to its account ID
account_id = await client.accounts.resolve_account_id(access_token, trader_login=12345678)