Skip to main content
Glama
VaishnaviK23

Trading MCP Server

by VaishnaviK23

validate_trades

Check trade history to ensure sell transactions do not exceed purchased share quantities, identifying any violations with specific error messages.

Instructions

Validate that no trades sell more shares than have been bought.

Parses the trade history sequentially to ensure all sell transactions occur only after a corresponding quantity of shares has been bought.

Returns: A list of error messages for invalid trades, if any.

Example: validate_trades() -> ["Invalid sell on 2024-02-10: 20 shares of AAPL (owned: 10)"]

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The validate_trades function iterates through the trade history dataframe and checks if sell orders exceed the currently owned shares, returning a list of violations.
    def validate_trades() -> list[str]:
        """Validate that no trades sell more shares than have been bought.
    
        Parses the trade history sequentially to ensure all sell transactions
        occur only after a corresponding quantity of shares has been bought.
    
        Returns:
            A list of error messages for invalid trades, if any.
    
        Example:
            validate_trades() -> ["Invalid sell on 2024-02-10: 20 shares of AAPL (owned: 10)"]
        """
        errors = []
        balances = defaultdict(int)
        for idx, row in df.iterrows():
            if row['type'] == 'Buy':
                balances[row['symbol']] += row['shares']
            else:
                if balances[row['symbol']] < row['shares']:
                    errors.append(f"Invalid sell on {row['date']}: {row['shares']} shares of {row['symbol']} (owned: {balances[row['symbol']]})")
                balances[row['symbol']] -= row['shares']
        return errors

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