Skip to main content
Glama
harshitdynamite

DhanHQ MCP Server

place_super_order

Execute a smart trading order with entry, target, and stop-loss legs in one action. Supports trailing stop loss for automated risk management.

Instructions

Places a smart super order combining entry, target, and stop-loss legs. Supports trailing stop loss. Requires authentication.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dhanClientIdYesYour Dhan client ID
correlationIdYesUnique correlation ID for order tracking
transactionTypeYes
exchangeSegmentYese.g., NSE_EQ, BSE_EQ
productTypeYes
orderTypeYes
securityIdYesSecurity ID for the instrument
quantityYesQuantity for entry leg
priceYesEntry price
targetPriceYesTarget price for profit booking
stopLossPriceYesStop loss price
trailingJumpNoTrailing stop loss jump amount (optional)

Implementation Reference

  • The handler function that implements the core logic for placing a super order via the Dhan API. It makes a POST request to the super orders endpoint with the provided request parameters.
    export async function placeSuperOrder(
      request: PlaceSuperOrderRequest
    ): Promise<OrderResponse> {
      try {
        log(
          `Placing super order: ${request.transactionType} ${request.quantity} shares with target ${request.targetPrice} and SL ${request.stopLossPrice}`
        );
    
        const response = await axios.post<OrderResponse>(
          'https://api.dhan.co/v2/super/orders',
          request,
          {
            headers: getApiHeaders(),
          }
        );
    
        log(
          `✓ Super order placed 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 place super order: ${errorMessage}`);
        throw new Error(`Failed to place super order: ${errorMessage}`);
      }
    }
  • Interface defining the input parameters and types for the placeSuperOrder handler, used for type safety and validation.
    export interface PlaceSuperOrderRequest {
      dhanClientId: string;
      correlationId: string;
      transactionType: 'BUY' | 'SELL';
      exchangeSegment: string;
      productType: 'CNC' | 'INTRADAY' | 'MARGIN' | 'MTF' | 'CO' | 'BO';
      orderType: 'LIMIT' | 'MARKET' | 'STOP_LOSS' | 'STOP_LOSS_MARKET';
      securityId: string;
      quantity: number;
      price: number;
      targetPrice: number;
      stopLossPrice: number;
      trailingJump?: number;
    }
  • src/index.ts:258-301 (registration)
    MCP tool registration including name, description, and input schema for listTools response.
    {
      name: 'place_super_order',
      description:
        'Places a smart super order combining entry, target, and stop-loss legs. Supports trailing stop loss. Requires authentication.',
      inputSchema: {
        type: 'object' as const,
        properties: {
          dhanClientId: { type: 'string', description: 'Your Dhan client ID' },
          correlationId: { type: 'string', description: 'Unique correlation ID for order tracking' },
          transactionType: { type: 'string', enum: ['BUY', 'SELL'] },
          exchangeSegment: { type: 'string', description: 'e.g., NSE_EQ, BSE_EQ' },
          productType: {
            type: 'string',
            enum: ['CNC', 'INTRADAY', 'MARGIN', 'MTF', 'CO', 'BO'],
          },
          orderType: {
            type: 'string',
            enum: ['MARKET', 'LIMIT', 'STOP_LOSS', 'STOP_LOSS_MARKET'],
          },
          securityId: { type: 'string', description: 'Security ID for the instrument' },
          quantity: { type: 'number', description: 'Quantity for entry leg' },
          price: { type: 'number', description: 'Entry price' },
          targetPrice: { type: 'number', description: 'Target price for profit booking' },
          stopLossPrice: { type: 'number', description: 'Stop loss price' },
          trailingJump: {
            type: 'number',
            description: 'Trailing stop loss jump amount (optional)',
          },
        },
        required: [
          'dhanClientId',
          'correlationId',
          'transactionType',
          'exchangeSegment',
          'productType',
          'orderType',
          'securityId',
          'quantity',
          'price',
          'targetPrice',
          'stopLossPrice',
        ],
      },
    },
  • src/index.ts:641-666 (registration)
    Dispatcher case in CallToolRequest handler that maps 'place_super_order' tool calls to the placeSuperOrder function.
    case 'place_super_order': {
      console.error('[Tool] Executing: place_super_order');
      const soArgs = args as Record<string, unknown>;
      const result = await placeSuperOrder({
        dhanClientId: soArgs.dhanClientId as string,
        correlationId: soArgs.correlationId as string,
        transactionType: soArgs.transactionType as 'BUY' | 'SELL',
        exchangeSegment: soArgs.exchangeSegment as string,
        productType: soArgs.productType as 'CNC' | 'INTRADAY' | 'MARGIN' | 'MTF' | 'CO' | 'BO',
        orderType: soArgs.orderType as 'LIMIT' | 'MARKET' | 'STOP_LOSS' | 'STOP_LOSS_MARKET',
        securityId: soArgs.securityId as string,
        quantity: soArgs.quantity as number,
        price: soArgs.price as number,
        targetPrice: soArgs.targetPrice as number,
        stopLossPrice: soArgs.stopLossPrice as number,
        trailingJump: soArgs.trailingJump as number | undefined,
      });
      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