Skip to main content
Glama
VaishnaviK23

Trading MCP Server

by VaishnaviK23

realized_gains

Calculate total realized gains using FIFO method by matching sell transactions with earliest buys in trade history.

Instructions

Calculate total realized gains using FIFO method.

This tool goes through the trade history and tracks all buy transactions in a FIFO queue. For each sell, it matches shares with the earliest buys and calculates the realized profit or loss accordingly.

Returns: A float representing the total realized gain or loss (in dollars), rounded to two decimal places.

Example: realized_gains() -> 352.75

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The 'realized_gains' tool function, registered with @mcp.tool(), implements the FIFO calculation for realized gains based on trade history.
    def realized_gains() -> float:
        """Calculate total realized gains using FIFO method.
    
        This tool goes through the trade history and tracks all buy transactions in a FIFO queue.
        For each sell, it matches shares with the earliest buys and calculates the realized profit
        or loss accordingly.
    
        Returns:
            A float representing the total realized gain or loss (in dollars), rounded to two decimal places.
    
        Example:
            realized_gains() -> 352.75
        """
        buy_queues = defaultdict(deque)
        gains = 0.0
    
        for _, row in df.iterrows():
            symbol = row['symbol']
            shares = row['shares']
            price = row['price_per_share']
            if row['type'] == 'Buy':
                buy_queues[symbol].append((shares, price))
            else:
                while shares > 0 and buy_queues[symbol]:
                    buy_shares, buy_price = buy_queues[symbol][0]
                    matched = min(shares, buy_shares)
                    gains += matched * (price - buy_price)
                    shares -= matched
                    if matched == buy_shares:
                        buy_queues[symbol].popleft()
                    else:
                        buy_queues[symbol][0] = (buy_shares - matched, buy_price)
        return round(gains, 2)
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full burden. Successfully discloses internal algorithm (FIFO queue processing, matching sells with earliest buys) and return format (float in dollars, rounded to two decimals). Missing safety/destructive traits and error conditions, but algorithmic transparency is high.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Well-structured with front-loaded purpose statement ('Calculate total realized gains using FIFO method'), followed by implementation details, return specification, and example. No extraneous content; every sentence earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a parameterless calculation tool, description adequately covers the complex FIFO methodology, data source (trade history), and return value semantics. Output schema exists in context, but description appropriately supplements it with units and precision details.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Zero parameters present with 100% schema coverage. Per rubric, 0 params establishes baseline of 4. Description appropriately focuses on behavioral explanation rather than parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Specific verb ('Calculate'), resource ('realized gains'), and methodology ('FIFO method') clearly stated. Explicitly distinguishes from sibling 'unrealized_gains' by specifying 'realized' and detailing the FIFO matching algorithm against trade history.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides implied usage context through the FIFO methodology explanation, but lacks explicit when-to-use guidance or comparison with alternatives (e.g., when to choose this over 'pnl' or 'unrealized_gains'). No exclusions or prerequisites mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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