Skip to main content
Glama
OFFICIAL_API_SPEC_UPDATE.md6.53 kB
# API Updated to Official DhanHQ Documentation Specifications ## Summary All order and super order endpoints have been updated to match the **official DhanHQ API v2.0 documentation** specifications. ## Key Changes ### 1. Endpoint URLs Updated to v2 All endpoints now use the v2 API path: - ✅ `/v2/orders` (was `/orders`) - ✅ `/v2/orders/{orderId}` (was `/orders/{orderId}`) - ✅ `/v2/orders/external/{correlationId}` (was `/orders/external/{correlationId}`) - ✅ `/v2/trades` (was `/trades`) - ✅ `/v2/trades/{orderId}` (was `/trades/{orderId}`) - ✅ `/v2/super/orders` (was `/super/orders`) - ✅ `/v2/super/orders/{orderId}` (was `/super/orders/{orderId}`) ### 2. Enum Values Updated to Official Spec **Product Types (productType):** - ❌ Removed: `MIS`, `NRML` - ✅ Added: `MARGIN`, `CO` (Cover Order), `BO` (Bracket Order) - **Current valid values**: `CNC` | `INTRADAY` | `MARGIN` | `MTF` | `CO` | `BO` **Order Types (orderType):** - ❌ Removed: `STOP`, `STOP_LIMIT` - ✅ Added: `STOP_LOSS`, `STOP_LOSS_MARKET` - **Current valid values**: `LIMIT` | `MARKET` | `STOP_LOSS` | `STOP_LOSS_MARKET` **Validity (validity):** - ❌ Removed: `TTL`, `GTC` - ✅ Kept: `DAY`, `IOC` - **Current valid values**: `DAY` | `IOC` ### 3. New Request Fields Added **PlaceOrderRequest now includes:** ```typescript disclosedQuantity?: number; // Quantity visible in order book (min 30%) afterMarketOrder?: boolean; // Flag for after-market orders amoTime?: 'PRE_OPEN' | 'OPEN' | 'OPEN_30' | 'OPEN_60'; boProfitValue?: number; // Bracket Order target price change boStopLossValue?: number; // Bracket Order stop loss price change ``` **ModifyOrderRequest now includes:** ```typescript disclosedQuantity?: number; // New disclosed quantity ``` ### 4. Type Definitions Updated **File: `src/types.ts`** - Updated `PlaceOrderRequest` interface with official spec - Updated `ModifyOrderRequest` interface with official spec - Updated `PlaceSuperOrderRequest` interface with official enums - All type casting in handlers updated accordingly ### 5. Tool Schemas Updated **File: `src/index.ts`** - Updated `place_order` tool schema with new fields and enums - Updated `modify_order` tool schema with official parameters - Updated `place_super_order` tool schema with official enums - All tool parameter descriptions now match official documentation ## Files Modified | File | Changes | |------|---------| | `src/types.ts` | 3 interface updates, enum values corrected | | `src/authentication.ts` | All 12 API functions updated to v2 endpoints | | `src/index.ts` | Tool schemas updated, type casting corrected | ## Build Status ✅ **TypeScript Compilation**: SUCCESS - Zero errors - Zero warnings - All types properly aligned with official spec - All 12 API functions compile without issues - All 20 MCP tools registered correctly ## API Endpoint Coverage ### Order Management v2 Endpoints | Method | Endpoint | Status | |--------|----------|--------| | POST | `/v2/orders` | ✅ Updated | | PUT | `/v2/orders/{orderId}` | ✅ Updated | | DELETE | `/v2/orders/{orderId}` | ✅ Updated | | GET | `/v2/orders` | ✅ Updated | | GET | `/v2/orders/{orderId}` | ✅ Updated | | GET | `/v2/orders/external/{correlationId}` | ✅ Updated | | GET | `/v2/trades` | ✅ Updated | | GET | `/v2/trades/{orderId}` | ✅ Updated | ### Super Order v2 Endpoints | Method | Endpoint | Status | |--------|----------|--------| | POST | `/v2/super/orders` | ✅ Updated | | PUT | `/v2/super/orders/{orderId}` | ✅ Updated | | DELETE | `/v2/super/orders/{orderId}/{leg}` | ✅ Updated | | GET | `/v2/super/orders` | ✅ Updated | ## Testing with Official Spec Now that the API is aligned with official documentation, here's how to test: ### Test Place Order (Official Spec) ```json { "dhanClientId": "1000000003", "correlationId": "123abc678", "transactionType": "BUY", "exchangeSegment": "NSE_EQ", "productType": "INTRADAY", "orderType": "MARKET", "validity": "DAY", "securityId": "11536", "quantity": 5, "price": 1500, "disclosedQuantity": 2, "afterMarketOrder": false } ``` ### Test with Stop Loss ```json { "dhanClientId": "1000000003", "correlationId": "sl_order_001", "transactionType": "BUY", "exchangeSegment": "NSE_EQ", "productType": "INTRADAY", "orderType": "STOP_LOSS", "validity": "DAY", "securityId": "11536", "quantity": 5, "price": 1500, "triggerPrice": 1450 } ``` ### Test with Bracket Order ```json { "dhanClientId": "1000000003", "correlationId": "bo_order_001", "transactionType": "BUY", "exchangeSegment": "NSE_EQ", "productType": "BO", "orderType": "LIMIT", "validity": "DAY", "securityId": "11536", "quantity": 5, "price": 1500, "boProfitValue": 100, "boStopLossValue": 50 } ``` ## Official Documentation Reference These changes are based on the official DhanHQ API v2.0 documentation: **Request Structure** - All endpoints now follow the v2.0 format - Headers: `Content-Type: application/json`, `access-token: JWT` - Request body matches official parameter specification **Supported Values** - Product Types: `CNC`, `INTRADAY`, `MARGIN`, `MTF`, `CO`, `BO` - Order Types: `LIMIT`, `MARKET`, `STOP_LOSS`, `STOP_LOSS_MARKET` - Validity: `DAY`, `IOC` - Transaction Types: `BUY`, `SELL` ## Backwards Compatibility ⚠️ **Breaking Changes:** - Old `MIS` and `NRML` product types no longer valid → Use `MARGIN` instead - Old `STOP` and `STOP_LIMIT` order types no longer valid → Use `STOP_LOSS` and `STOP_LOSS_MARKET` - Old `TTL` and `GTC` validity no longer supported → Use `DAY` or `IOC` If migrating from older code, update: - `MIS` → `MARGIN` - `NRML` → `MARGIN` or `CNC` - `STOP` → `STOP_LOSS` - `STOP_LIMIT` → `STOP_LOSS_MARKET` - `TTL` → `DAY` or `IOC` - `GTC` → `DAY` or `IOC` ## Next Steps 1. **Test with Official Spec**: Use the test examples above to verify order placement 2. **Verify Enum Values**: Ensure you're using the official enum values from the documentation 3. **Check New Fields**: Consider using new fields like `disclosedQuantity`, `afterMarketOrder`, `boProfitValue`, `boStopLossValue` for advanced trading strategies 4. **Monitor API Responses**: Watch for any field updates in API responses that might be new in v2 ## Deployment The updated MCP server is production-ready: ```bash # Build npm run build # Run npm start # Test with Inspector npm run inspector ``` All 20 tools are available and aligned with official DhanHQ API v2.0 specifications.

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