get_positions
Retrieve current portfolio positions and cash balance for portfolio management and trading analysis.
Instructions
Retrieves the current state of all held positions and cash balance.
Returns:
Dict with 'cash' and 'positions' keys
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- tools/execution.py:18-54 (handler)The primary handler function for the 'get_positions' tool. It fetches the current portfolio positions, cash balance, equity, and buying power from the Alpaca trading broker, handling errors gracefully.def get_positions() -> Dict[str, Any]: """ Retrieves the current state of all held positions and cash balance. Returns: Dict with 'cash' and 'positions' keys """ if broker is None: return { "error": "Alpaca broker not initialized. Check your API credentials.", "cash": 0, "positions": {} } try: account = broker.get_account() positions_raw = broker.get_all_positions() # Convert to simple format: {symbol: qty} positions = { symbol: details['qty'] for symbol, details in positions_raw.items() } return { "cash": account['cash'], "equity": account['equity'], "buying_power": account['buying_power'], "positions": positions } except Exception as e: logger.error(f"Failed to get positions: {e}") return { "error": str(e), "cash": 0, "positions": {} }
- server.py:375-378 (registration)Registration of the 'get_positions' tool (along with other execution tools) in the MCP server using the register_tools helper, which applies the @mcp.tool() decorator.register_tools( [place_order, cancel_order, get_positions, flatten, get_order_history], "Execution" )
- app.py:288-288 (registration)Inclusion of 'get_positions' in the tools_map for the Gradio UI which also supports MCP server mode."Execution": [place_order, cancel_order, get_positions, flatten, get_order_history],