Documentation Index
Fetch the complete documentation index at: https://finance.dev/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The Accounts API provides access to account-level data including balances, buying power, positions, and order history for specific trading accounts.
Class Reference
from aries_exchange import AriesClient
client = AriesClient(
client_id="your_client_id",
client_secret="your_client_secret"
)
# Access accounts methods
accounts = client.accounts
Methods
get_balances(account_id)
Retrieve account balances and buying power.
balances = client.accounts.get_balances(account_id="acc_123456")
print(f"Cash: ${balances.cash}")
print(f"Buying Power: ${balances.buying_power}")
print(f"Portfolio Value: ${balances.portfolio_value}")
Parameters:
account_id (str): Account ID
Returns: Balances object
get_orders(account_id, status=None)
Retrieve all orders for an account.
# Get all orders
orders = client.accounts.get_orders(account_id="acc_123456")
# Get only open orders
open_orders = client.accounts.get_orders(
account_id="acc_123456",
status="open"
)
Parameters:
account_id (str): Account ID
status (str, optional): Filter by status (“open”, “filled”, “cancelled”)
Returns: List of Order objects
get_positions(account_id)
Retrieve all positions for an account.
positions = client.accounts.get_positions(account_id="acc_123456")
for position in positions:
print(f"{position.symbol}: {position.quantity} shares")
print(f" P/L: ${position.unrealized_pl}")
Parameters:
account_id (str): Account ID
Returns: List of Position objects
Data Objects
Balances Object
{
"cash": 10000.00,
"buying_power": 40000.00,
"portfolio_value": 50000.00,
"equity": 45000.00,
"long_market_value": 35000.00,
"short_market_value": 0.00,
"day_trading_buying_power": 40000.00,
"overnight_buying_power": 20000.00
}
Position Object
{
"symbol": "AAPL",
"quantity": 100,
"average_cost": 145.50,
"current_price": 150.75,
"market_value": 15075.00,
"unrealized_pl": 525.00,
"unrealized_pl_percent": 3.61,
"side": "long"
}
Examples
Check Account Balance Before Trading
# Get account balances
balances = client.accounts.get_balances(account_id="acc_123456")
print(f"Available cash: ${balances.cash:,.2f}")
print(f"Buying power: ${balances.buying_power:,.2f}")
# Check if sufficient funds for trade
order_cost = 1500.00
if balances.buying_power >= order_cost:
print("Sufficient funds to place order")
order = client.orders.place_order(
symbol="AAPL",
quantity=10,
side="buy",
order_type="market"
)
else:
print(f"Insufficient funds. Need ${order_cost - balances.buying_power:,.2f} more")
Monitor Account Positions
# Get all positions
positions = client.accounts.get_positions(account_id="acc_123456")
print(f"Total positions: {len(positions)}\n")
total_pl = 0
for position in positions:
print(f"{position.symbol}:")
print(f" Quantity: {position.quantity}")
print(f" Avg Cost: ${position.average_cost:.2f}")
print(f" Current: ${position.current_price:.2f}")
print(f" Value: ${position.market_value:,.2f}")
print(f" P/L: ${position.unrealized_pl:,.2f} ({position.unrealized_pl_percent:+.2f}%)")
print()
total_pl += position.unrealized_pl
print(f"Total Unrealized P/L: ${total_pl:,.2f}")
Review Order History
# Get all orders for the account
orders = client.accounts.get_orders(account_id="acc_123456")
print(f"Total orders: {len(orders)}\n")
# Group by status
from collections import defaultdict
orders_by_status = defaultdict(list)
for order in orders:
orders_by_status[order.status].append(order)
for status, order_list in orders_by_status.items():
print(f"{status.upper()}: {len(order_list)} orders")
# Show recent filled orders
filled_orders = [o for o in orders if o.status == "filled"]
filled_orders.sort(key=lambda x: x.filled_at, reverse=True)
print("\nRecent Fills:")
for order in filled_orders[:5]:
print(f"{order.symbol} - {order.side.upper()} {order.quantity} @ ${order.average_fill_price:.2f}")
# Get balances and positions
balances = client.accounts.get_balances(account_id="acc_123456")
positions = client.accounts.get_positions(account_id="acc_123456")
# Calculate metrics
total_investment = sum(p.quantity * p.average_cost for p in positions)
total_value = sum(p.market_value for p in positions)
unrealized_pl = total_value - total_investment
# Account summary
print("Account Performance Summary:")
print(f"Cash: ${balances.cash:,.2f}")
print(f"Investment: ${total_investment:,.2f}")
print(f"Current Value: ${total_value:,.2f}")
print(f"Unrealized P/L: ${unrealized_pl:,.2f}")
print(f"Return: {(unrealized_pl / total_investment * 100):+.2f}%")
print(f"Total Equity: ${balances.equity:,.2f}")
Find Winning and Losing Positions
positions = client.accounts.get_positions(account_id="acc_123456")
# Sort by P/L
positions.sort(key=lambda x: x.unrealized_pl, reverse=True)
print("Top Winners:")
for position in positions[:3]:
if position.unrealized_pl > 0:
print(f"{position.symbol}: ${position.unrealized_pl:,.2f} (+{position.unrealized_pl_percent:.2f}%)")
print("\nTop Losers:")
for position in positions[-3:]:
if position.unrealized_pl < 0:
print(f"{position.symbol}: ${position.unrealized_pl:,.2f} ({position.unrealized_pl_percent:.2f}%)")
Error Handling
from aries_exchange import AriesAPIError
try:
balances = client.accounts.get_balances(account_id="acc_123456")
except AriesAPIError as e:
if e.status_code == 403:
print("Access denied: You don't have permission for this account")
elif e.status_code == 404:
print("Account not found")
else:
print(f"Error: {e.message}")
Best Practices
- Check balances before trading to avoid insufficient funds errors
- Monitor positions regularly to stay informed about P/L
- Use filters when querying orders to reduce data transfer
- Store account data appropriately to minimize API calls
- Handle errors gracefully especially for permission issues
- Orders - Place and manage orders
- Users - Get list of user accounts
- Market Data - Get current prices for positions
API Endpoints
This SDK wraps the following REST API endpoints:
GET /v1/accounts/{id}/balances - Get account balances
GET /v1/accounts/{id}/orders - Get account orders
GET /v1/accounts/{id}/positions - Get account positions