DhanHQ Historical Data API Returning HTTP 500 - Need Help
Problem Summary
Getting consistent HTTP 500 Internal Server Error from DhanHQ’s historical data API endpoints, even with correct request format matching official
documentation. Need community help to identify what might be wrong.
Environment
- API Version: v2
- Endpoints:
/v2/charts/historical
(daily) and/v2/charts/intraday
(minute) - Client ID: 1106283829
- Language: C# (.NET)
Code Examples
Working cURL Command Structure
# Daily Historical Data
curl -X POST "https://api.dhan.co/v2/charts/historical" \
-H "Content-Type: application/json" \
-H "access-token: YOUR_JWT_TOKEN" \
-H "client-id: YOUR_CLIENT_ID" \
-d '{
"securityId": "1333",
"exchangeSegment": "NSE_EQ",
"instrument": "EQUITY",
"expiryCode": 0,
"oi": false,
"fromDate": "2025-08-28",
"toDate": "2025-09-04"
}'
# Intraday Historical Data
curl -X POST "https://api.dhan.co/v2/charts/intraday" \
-H "Content-Type: application/json" \
-H "access-token: YOUR_JWT_TOKEN" \
-H "client-id: YOUR_CLIENT_ID" \
-d '{
"securityId": "1333",
"exchangeSegment": "NSE_EQ",
"instrument": "EQUITY",
"interval": "1",
"oi": false,
"fromDate": "2025-09-03 09:30:00",
"toDate": "2025-09-04 15:30:00"
}'
C# Implementation
public async Task<List<OHLC>> GetHistoricalDataAsync(string symbol, string timeFrame, DateTime from, DateTime to)
{
var securityInfo = DhanSecurityMaster.GetSecurityInfo(symbol);
if (securityInfo == null) return new List<OHLC>();
bool isDailyData = timeFrame.Equals("1DAY", StringComparison.OrdinalIgnoreCase);
object request;
string endpoint;
if (isDailyData)
{
request = new
{
securityId = securityInfo.SecurityId,
exchangeSegment = securityInfo.ExchangeSegment,
instrument = securityInfo.InstrumentType,
expiryCode = 0,
oi = false,
fromDate = from.ToString("yyyy-MM-dd"),
toDate = to.ToString("yyyy-MM-dd")
};
endpoint = "/v2/charts/historical";
}
else
{
request = new
{
securityId = securityInfo.SecurityId,
exchangeSegment = securityInfo.ExchangeSegment,
instrument = securityInfo.InstrumentType,
interval = timeFrame,
oi = false,
fromDate = from.ToString("yyyy-MM-dd HH:mm:ss"),
toDate = to.ToString("yyyy-MM-dd HH:mm:ss")
};
endpoint = "/v2/charts/intraday";
}
// This throws HTTP 500 error consistently
var response = await PostAsync<HistoricalDataResponse>(endpoint, request);
return response?.Data ?? new List<OHLC>();
}
What I've Verified ✅
1. Request Format: Matches official docs exactly - includes expiryCode, oi, proper date formats
2. Endpoints: Using correct /v2/charts/historical and /v2/charts/intraday
3. Authentication: Headers access-token and client-id are correct and valid
4. Security Master: Using valid securityId (1333 for RELIANCE), exchangeSegment (NSE_EQ), instrument (EQUITY)
5. Rate Limiting: Implemented proper throttling and retry mechanisms
6. Date Ranges: Tried various date ranges including recent dates
7. Symbols: Tested with multiple symbols (RELIANCE, NIFTY, etc.)
Error Details
- HTTP Status: 500 Internal Server Error
- Response: Empty body or generic error message
- Frequency: 100% of requests failing
- Timing: Issue started recently, worked before
Questions for Community
1. Is anyone else experiencing HTTP 500 errors with historical data APIs in the past few days?
2. Are there any undocumented required fields or different request format for historical data?
3. Should I be using different endpoints or base URL for historical data?
4. Is there a data subscription requirement that might cause 500 errors. I have taken the subsription as well.
5. Are there specific symbols or date ranges that work better than others?
Additional Context
- Other DhanHQ APIs (quotes, option chains) have similar issues (429/500 errors)
- Sandbox API also returns validation errors
- Using production access token and client ID
- Rate limiting properly implemented (max 10 concurrent requests)
Request for Help
If you have working historical data API calls with DhanHQ, could you please share:
- Your exact request format
- Any special headers or parameters
- Date range limitations you've discovered
- Whether you needed special API subscription
Thanks for any insights!