asynctradier.clients.account_clients module

class asynctradier.clients.account_clients.AccountClient(session: WebUtil, account_id: str, token: str, sandbox: bool = False)[source]

Bases: object

A client for interacting with the Tradier Account API.

Parameters:
  • session (WebUtil) – The session object used for making HTTP requests.

  • account_id (str) – The account ID.

  • token (str) – The API token.

  • sandbox (bool, optional) – Whether to use the sandbox environment. Defaults to False.

async get_balance() AccountBalance[source]

Retrieves the account balance.

Returns:

The account balance.

Return type:

AccountBalance

async get_gainloss(page: int = 1, limit: int = 25, start: str | None = None, end: str | None = None, symbol: str | None = None, sort_by_close_date: bool = True, desc: bool = True) List[ProfitLoss][source]

Retrieves the gain/loss information for closed positions within a specified date range.

Parameters:
  • page (int) – The page number of the results to retrieve (default is 1).

  • limit (int) – The maximum number of results per page (default is 25).

  • start (str, optional) – The start date of the date range (format: “YYYY-MM-DD”).

  • end (str, optional) – The end date of the date range (format: “YYYY-MM-DD”).

  • symbol (str, optional) – The symbol of the positions to filter by.

  • sort_by_close_date (bool) – Whether to sort the results by close date (default is False).

  • desc (bool) – Whether to sort the results in descending order (default is True).

Returns:

A list of ProfitLoss objects representing the gain/loss information.

Return type:

List[ProfitLoss]

Raises:

InvalidDateFormat – If the start or end date is not in the correct format.

async get_history(page: int = 1, limit: int = 25, event_type: EventType | None = None, start: str | None = None, end: str | None = None, symbol: str | None = None, exact_match: bool = False) List[Event][source]

Retrieves the account history.

Parameters:
  • page (int, optional) – The page number of the history to retrieve. Defaults to 1.

  • limit (int, optional) – The number of events to retrieve per page. Defaults to 25.

  • event_type (EventType, optional) – The type of event to retrieve. Defaults to None.

  • start (str, optional) – The start date of the history to retrieve (YYYY-MM-DD). Defaults to None.

  • end (str, optional) – The end date of the history to retrieve (YYYY-MM-DD). Defaults to None.

  • symbol (str, optional) – The symbol of the event to retrieve. Defaults to None.

  • exact_match (bool, optional) – Whether to perform an exact match on the symbol. Defaults to False.

Returns:

A list of Event objects representing the account history.

Return type:

List[Event]

async get_order(order_id: str) Order[source]

Get an order by its ID.

Parameters:

order_id (str) – The ID of the order.

Returns:

The Order object.

Return type:

Order

async get_orders(page: int = 1) List[Order][source]

Get a list of orders for the account.

Parameters:

page (int, optional) – The page number of the orders to retrieve. Defaults to 1.

Returns:

A list of Order objects.

Return type:

List[Order]

async get_positions() List[Position][source]

Get the positions for the account.

Returns:

A list of Position objects.

Return type:

List[Position]

async get_user_profile() List[UserAccount][source]

Retrieves the user profile information.

Returns:

A list of UserProfile objects representing the user’s profile information.