Skip to main content
Glama
harshitdynamite

DhanHQ MCP Server

get_order_trades

Retrieve all trade executions for a specific order to track partial fills or bracket/cover order outcomes. Requires authentication with DhanHQ trading APIs.

Instructions

Retrieves all trades for a specific order. Useful for partial fills or bracket/cover orders. Requires authentication.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
orderIdYesOrder ID to get trades for

Implementation Reference

  • The core handler function that executes the get_order_trades tool logic by fetching trades for the given orderId from the Dhan API endpoint and returning TradeBook[]
    export async function getOrderTrades(orderId: string): Promise<TradeBook[]> {
      try {
        log(`Fetching trades for order: ${orderId}`);
    
        const response = await axios.get<TradeBook[]>(
          `https://api.dhan.co/v2/trades/${orderId}`,
          {
            headers: getApiHeaders(),
          }
        );
    
        log(`✓ Trades retrieved. Total trades: ${response.data.length}`);
        return response.data;
      } catch (error) {
        const errorMessage =
          error instanceof axios.AxiosError
            ? `API Error: ${error.response?.status} - ${JSON.stringify(error.response?.data)}`
            : error instanceof Error
              ? error.message
              : 'Unknown error';
    
        log(`✗ Failed to get order trades: ${errorMessage}`);
        throw new Error(`Failed to get order trades: ${errorMessage}`);
      }
    }
  • Input schema and metadata for the 'get_order_trades' tool, defining the required 'orderId' parameter.
    {
      name: 'get_order_trades',
      description:
        'Retrieves all trades for a specific order. Useful for partial fills or bracket/cover orders. Requires authentication.',
      inputSchema: {
        type: 'object' as const,
        properties: {
          orderId: { type: 'string', description: 'Order ID to get trades for' },
        },
        required: ['orderId'],
      },
    },
  • src/index.ts:626-638 (registration)
    Registration and dispatch logic in the main tool handler switch statement that matches the tool name, extracts arguments, calls the getOrderTrades function, and returns the formatted response.
    case 'get_order_trades': {
      console.error('[Tool] Executing: get_order_trades');
      const { orderId } = args as Record<string, unknown>;
      const trades = await getOrderTrades(orderId as string);
      return {
        content: [
          {
            type: 'text' as const,
            text: JSON.stringify(trades, null, 2),
          },
        ],
      };
    }
  • TypeScript interface defining the structure of a TradeBook object, used as the return type for getOrderTrades.
    export interface TradeBook {
      dhanClientId: string;
      orderId: string;
      exchangeOrderId: string;
      exchangeTradeId: string;
      transactionType: string;
      exchangeSegment: string;
      tradingSymbol: string;
      tradedQuantity: number;
      tradedPrice: number;
      exchangeTime: string;
    }
  • src/index.ts:22-22 (registration)
    Import of the getOrderTrades handler function from authentication module.
    getOrderTrades,
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'Requires authentication,' which is a useful context for security needs. However, it lacks details on other behavioral traits such as rate limits, error handling, response format, or whether it's read-only (implied by 'Retrieves' but not explicit). For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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

Conciseness4/5

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

The description is appropriately sized with three concise sentences that each serve a purpose: stating the action, providing usage context, and noting authentication. It is front-loaded with the core purpose, but could be slightly more structured by explicitly separating guidelines. Overall, it is efficient with minimal waste.

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

Completeness3/5

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

Given the tool's complexity (a read operation with one parameter) and the absence of annotations and output schema, the description is somewhat complete but has gaps. It covers the purpose and authentication need but lacks details on return values, error cases, or behavioral constraints. For a tool without structured output information, it should provide more context to be fully helpful.

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

Parameters3/5

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

The input schema has 100% description coverage, with the parameter 'orderId' clearly documented. The description does not add any additional meaning or context beyond what the schema provides, such as format examples or constraints. Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description neither compensates for gaps nor enhances parameter understanding.

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

Purpose4/5

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

The description clearly states the tool's purpose with a specific verb ('Retrieves') and resource ('all trades for a specific order'), making it easy to understand what it does. However, it does not explicitly differentiate from sibling tools like 'get_trade_book' or 'get_order_by_id', which might have overlapping functionality, so it falls short of a perfect score.

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?

The description provides implied usage guidance by mentioning 'Useful for partial fills or bracket/cover orders,' which suggests contexts where this tool is applicable. However, it does not explicitly state when to use this tool versus alternatives like 'get_trade_book' or 'get_order_by_id,' nor does it provide exclusions or clear prerequisites beyond authentication.

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/harshitdynamite/DhanMCP'

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