Skip to main content
Glama
harshitdynamite

DhanHQ MCP Server

cancel_super_order_leg

Cancel a specific leg (ENTRY_LEG, TARGET_LEG, or STOP_LOSS_LEG) of a super order in DhanHQ trading by providing the order ID and leg type.

Instructions

Cancels a specific leg of a super order (ENTRY_LEG, TARGET_LEG, or STOP_LOSS_LEG). Requires authentication.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
orderIdYesSuper order ID
orderLegYesWhich leg to cancel

Implementation Reference

  • The core handler function that performs the API call to cancel a specific leg of a super order using the Dhan API.
    export async function cancelSuperOrderLeg(
      orderId: string,
      orderLeg: string
    ): Promise<OrderResponse> {
      try {
        log(
          `Cancelling super order leg: ${orderId}, leg: ${orderLeg}`
        );
    
        const response = await axios.delete<OrderResponse>(
          `https://api.dhan.co/v2/super/orders/${orderId}/${orderLeg}`,
          {
            headers: getApiHeaders(),
          }
        );
    
        log(
          `✓ Super order leg cancelled successfully. Order ID: ${response.data.orderId}`
        );
        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 cancel super order leg: ${errorMessage}`);
        throw new Error(`Failed to cancel super order leg: ${errorMessage}`);
      }
  • Defines the tool schema including name, description, and input validation schema for parameters orderId and orderLeg.
    {
      name: 'cancel_super_order_leg',
      description:
        'Cancels a specific leg of a super order (ENTRY_LEG, TARGET_LEG, or STOP_LOSS_LEG). Requires authentication.',
      inputSchema: {
        type: 'object' as const,
        properties: {
          orderId: { type: 'string', description: 'Super order ID' },
          orderLeg: {
            type: 'string',
            enum: ['ENTRY_LEG', 'TARGET_LEG', 'STOP_LOSS_LEG'],
            description: 'Which leg to cancel',
          },
        },
        required: ['orderId', 'orderLeg'],
      },
  • src/index.ts:686-701 (registration)
    Registers the tool handler in the MCP server's request handler switch statement, extracting arguments and calling the cancelSuperOrderLeg function.
    case 'cancel_super_order_leg': {
      console.error('[Tool] Executing: cancel_super_order_leg');
      const { orderId, orderLeg } = args as Record<string, unknown>;
      const result = await cancelSuperOrderLeg(
        orderId as string,
        orderLeg as string
      );
      return {
        content: [
          {
            type: 'text' as const,
            text: JSON.stringify(result, null, 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/harshitdynamite/DhanMCP'

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