Skip to main content
Glama
laukikk

Alpaca Trading MCP Server

by laukikk

close_position

Close an open trading position for a specific stock symbol using the Alpaca Trading MCP Server to manage your portfolio.

Instructions

Close an open position for a specific symbol.

Args: symbol: Stock symbol to close position for

Returns: Confirmation of position closure

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes

Implementation Reference

  • The handler function decorated with @mcp.tool() that implements the close_position tool. It checks for an existing position and calls the Alpaca trading client to close it.
    @mcp.tool() def close_position(symbol: str) -> str: """ Close an open position for a specific symbol. Args: symbol: Stock symbol to close position for Returns: Confirmation of position closure """ try: # First check if position exists position = calls.get_position(trading_client, symbol) if not position: return f"No open position found for {symbol}." # Close the position trading_client.close_position(symbol) return f"Position for {symbol} has been successfully closed." except Exception as e: return f"Error closing position for {symbol}: {str(e)}"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/laukikk/alpaca-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server