Margin Request API Returning DH-905 Error Despite Correct Payload

Is the Margin Request API currently working? I’m encountering an error even though I’m sending the payload exactly as specified in the documentation.

Request Payload:

{
  "dhanClientId": "XXXX",
  "exchangeSegment": "NSE_EQ",
  "transactionType": "BUY",
  "quantity": 5,
  "productType": "CNC",
  "securityId": "2885",
  "price": 1428,
  "triggerPrice": 1427
}

Response:

{
  "errorType": "Input_Exception",
  "errorCode": "DH-905",
  "errorMessage": "Missing required fields, bad values for parameters etc."
}

The error message is quite generic and does not indicate which specific field is missing or invalid, which makes debugging difficult.

Could someone please confirm whether the Margin Request API is functioning correctly, or if there have been any recent changes to the required parameters?

Any guidance would be appreciated.

this is the code that i am trying to execute

from __future__ import annotations

import json
import os
import subprocess
import sys
from dotenv import load_dotenv


def main() -> int:
    load_dotenv()

    access_token = os.getenv("DHAN_ACCESS_TOKEN")
    client_id = os.getenv("DHAN_CLIENT_ID")

    if not access_token:
        print("DHAN_ACCESS_TOKEN not found in .env", file=sys.stderr)
        return 1

    if not client_id:
        print("DHAN_CLIENT_ID not found in .env", file=sys.stderr)
        return 1

    payload = {
        "dhanClientId": client_id,
        "exchangeSegment": "NSE_EQ",
        "transactionType": "BUY",
        "quantity": 5,
        "productType": "CNC",
        "securityId": "2885",
        "price": 1428,
        "triggerPrice": 1427,
    }

    print("Request Payload:", json.dumps(payload, indent=2))

    command = [
        "curl",
        "--silent",
        "--show-error",
        "--request", "POST",
        "--url", "https://api.dhan.co/v2/margincalculator",
        "--header", "Accept: application/json",
        "--header", "Content-Type: application/json",
        "--header", f"access-token: {access_token}",
        "--data", json.dumps(payload),
    ]

    result = subprocess.run(command, capture_output=True, text=True)

    if result.stdout:
        print(result.stdout)

    if result.stderr:
        print(result.stderr, file=sys.stderr)

    return result.returncode


if __name__ == "__main__":
    raise SystemExit(main())

@Srinadha_Reddy1 May be because of weekend. “Margin Required” is not working on the website as well.

1 Like
2026-04-03T09:31:56.230435+05:30 [info     ] http_outbound_response         body='{"errorType":"Input_Exception","errorCode":"DH-905","errorMessage":"Missing required fields, bad values for parameters etc."}' component=dhan.http headers={'content-type': 'application/json', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'date': 'Fri, 03 Apr 2026 04:01:58 GMT', 'content-security-policy': "frame-ancestors 'none'", 'x-frame-options': 'SAMEORIGIN', 'vary': 'Origin, Access-Control-Request-Method, Access-Control-Request-Headers', 'x-cache': 'Error from cloudfront', 'via': '1.1 f0b4d967b3ec06f75167a5f4422a9df0.cloudfront.net (CloudFront)', 'x-amz-cf-pop': 'MAA50-P2', 'alt-svc': 'h3=":443"; ma=86400', 'x-amz-cf-id': 'YmJtSoytVUd0mPy7NVrqJd9rZ2BqDZwwAc1hYqyNUxLDx9UjIQSE7A=='} operation=calculate_margin status_code=400 url=https://api.dhan.co/v2/margincalculator
2026-04-03T09:31:56.230974+05:30 [error    ] dhan.request_error             body='{"errorType":"Input_Exception","errorCode":"DH-905","errorMessage":"Missing required fields, bad values for parameters etc."}' component=dhan.http operation=calculate_margin status_code=400

Hi Team,

I’m currently integrating with the Margin Calculator API (/v2/margincalculator) and facing an issue with error handling.

The API returns a generic error:
DH-905: Missing required fields, bad values for parameters etc.

While I understand this indicates a validation failure, the response does not provide any field-level details about what exactly is missing or invalid. This makes debugging quite difficult from a developer’s perspective.

Could you please help clarify:

  1. Is there a way to get more granular validation errors (e.g., which specific field is incorrect or missing)?

  2. Does the API strictly enforce the documented request schema, or are there any undocumented constraints we should be aware of?

  3. Are there any sample requests/responses that are guaranteed to work for reference?

Providing more detailed error messages would greatly improve the developer experience and speed up integrations.

Thanks in advance for your support.