get_account_info
Retrieve detailed Alpaca account data such as equity, buying power, and day trade status for portfolio management and trading strategy development.
Instructions
Get detailed Alpaca account information including equity, buying power, and day trade status.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.py:37-56 (handler)Primary MCP tool handler for 'get_account_info'. Decorated with @mcp.tool() for automatic registration. Retrieves and formats Alpaca brokerage account details including cash, equity, buying power, PDT status.@mcp.tool() def get_account_info() -> str: """ Get detailed Alpaca account information including equity, buying power, and day trade status. """ try: broker = get_broker() account = broker.get_account() return f""" === ALPACA ACCOUNT INFO === Cash: ${account['cash']:,.2f} Equity: ${account['equity']:,.2f} Buying Power: ${account['buying_power']:,.2f} Portfolio Value: ${account['portfolio_value']:,.2f} Pattern Day Trader: {account['pattern_day_trader']} Day Trade Count: {account['daytrade_count']} """ except Exception as e: return f"ERROR: Failed to get account info - {str(e)}"
- tools/alpaca_broker.py:54-74 (helper)AlpacaBroker.get_account() method called by get_account_info to fetch raw account data from Alpaca API.def get_account(self) -> Dict[str, Any]: """ Retrieve account information. Returns: Dict with keys: cash, equity, buying_power, portfolio_value """ try: account = self.trading_client.get_account() return { "cash": float(account.cash), "equity": float(account.equity), "buying_power": float(account.buying_power), "portfolio_value": float(account.portfolio_value), "pattern_day_trader": account.pattern_day_trader, "daytrade_count": account.daytrade_count } except Exception as e: logger.error(f"Failed to get account: {e}") raise
- tools/alpaca_broker.py:332-337 (helper)Singleton factory function get_broker() that provides the AlpacaBroker instance used in get_account_info.def get_broker() -> AlpacaBroker: """Get or create the Alpaca broker singleton.""" global _broker if _broker is None: _broker = AlpacaBroker() return _broker
- server.py:37-56 (registration)The @mcp.tool() decorator registers get_account_info as an MCP tool.@mcp.tool() def get_account_info() -> str: """ Get detailed Alpaca account information including equity, buying power, and day trade status. """ try: broker = get_broker() account = broker.get_account() return f""" === ALPACA ACCOUNT INFO === Cash: ${account['cash']:,.2f} Equity: ${account['equity']:,.2f} Buying Power: ${account['buying_power']:,.2f} Portfolio Value: ${account['portfolio_value']:,.2f} Pattern Day Trader: {account['pattern_day_trader']} Day Trade Count: {account['daytrade_count']} """ except Exception as e: return f"ERROR: Failed to get account info - {str(e)}"
- app.py:104-118 (helper)UI helper version of get_account_info used in Gradio dashboard.def get_account_info() -> str: try: broker = get_broker() account = broker.get_account() return f""" === ALPACA ACCOUNT INFO === Cash: ${account['cash']:,.2f} Equity: ${account['equity']:,.2f} Buying Power: ${account['buying_power']:,.2f} Portfolio Value: ${account['portfolio_value']:,.2f} Pattern Day Trader: {account['pattern_day_trader']} Day Trade Count: {account['daytrade_count']} """ except Exception as e: return f"ERROR: Failed to get account info - {str(e)}"