Skip to main content
Glama
VaishnaviK23

Trading MCP Server

by VaishnaviK23

simulate_sell

Estimate profit or loss by simulating stock sales with FIFO matching. Enter a stock symbol and share quantity to calculate potential returns.

Instructions

Simulate selling a number of shares of a stock and estimate the profit or loss.

Args: symbol: The stock ticker symbol to simulate the sale for (e.g., TSLA) shares: The number of shares to simulate selling.

Returns: The estimated profit/loss from the simulated sale using FIFO matching, in dollars.

Example: simulate_sell("AAPL", 50) -> 123.45

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes
sharesYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The 'simulate_sell' tool is registered using @mcp.tool() and implements logic to calculate the estimated profit/loss of a stock sale using FIFO matching, based on current holdings derived from a CSV and the live market price.
    @mcp.tool()
    def simulate_sell(symbol: str, shares: int) -> float:
        """Simulate selling a number of shares of a stock and estimate the profit or loss.
    
        Args:
            symbol: The stock ticker symbol to simulate the sale for (e.g., TSLA)
            shares: The number of shares to simulate selling.
    
        Returns:
            The estimated profit/loss from the simulated sale using FIFO matching, in dollars.
    
        Example:
            simulate_sell("AAPL", 50) -> 123.45
        """
        # Build current holdings for this symbol
        holdings = []
        for _, row in df.iterrows():
            if row['symbol'] != symbol:
                continue
            if row['type'] == 'Buy':
                holdings.append((row['shares'], row['price_per_share']))
            else:
                to_sell = row['shares']
                while to_sell > 0 and holdings:
                    qty, price = holdings[0]
                    matched = min(qty, to_sell)
                    if matched == qty:
                        holdings.pop(0)
                    else:
                        holdings[0] = (qty - matched, price)
                    to_sell -= matched
    
        proceeds = 0.0
        sell_price = get_live_price(symbol)
        to_sell = shares
    
        while to_sell > 0 and holdings:
            qty, buy_price = holdings[0]
            matched = min(qty, to_sell)
            proceeds += matched * (sell_price - buy_price)
            if matched == qty:
                holdings.pop(0)
            else:
                holdings[0] = (qty - matched, buy_price)
            to_sell -= matched
    
        return round(proceeds, 2)

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/VaishnaviK23/Trading-MCP-Server'

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