Forever Order on V2 API

Hi DhanHQ API team and community,

I’ve been working with the v2 DhanHQ API, specifically with placing forever orders using the endpoint described at Forever Order - DhanHQ Ver 1.0 / API Document. I’ve run into an issue that I’m hoping someone can help me with or investigate.

When placing a forever order using the curl method, I’ve noticed that setting “productType”: “CNC” works fine and successfully places the order. However, when I try to use “productType”: “MTF”, it doesn’t work and returns an error.

“Order 7 response: 400 - {“errorType”:“Order_Error”,“errorCode”:“DH-906”,“errorMessage”:“Missing required fields, bad values for parameters etc.”}”

Here’s an example of the curl command I’m using:

curl --request POST \
    --url https://api.dhan.co/v2/forever/orders \
    --header 'Accept: application/json' \
    --header 'Content-Type: application/json' \
    --header 'access-token: <my-access-token>' \
    --data '{
        "dhanClientId": "1000000132",
        "orderFlag": "SINGLE",
        "transactionType": "BUY",
        "exchangeSegment": "NSE_EQ",
        "productType": "MTF",
        "orderType": "LIMIT",
        "validity": "DAY",
        "securityId": "1333",
        "quantity": 5,
        "disclosedQuantity": 1,
        "price": 1428,
        "triggerPrice": 1427
    }'

it is implemented, please check the v2 docs, but not going through the api, Dhan API

@Hardik @Sammy Please help

Hi @thiru ,
Can you share exact code which you are running, if possible?
DH-906 means Incorrect request for order and cannot be processed.
So data POST’ed to system seems to be incorrect.

This is the code

import http.client
import json

# Define the API endpoint and headers
conn = http.client.HTTPSConnection("api.dhan.co")

# Loop through each row in the DataFrame
for index, row in df_with_scrip_id.iterrows():
    
    order_data = {
        "dhanClientId": "11111111",
        "correlationId": "",
        "orderFlag": "SINGLE",
        "transactionType": "BUY",
        "exchangeSegment": "NSE_EQ",
        "productType": "MTF",
        "orderType": "LIMIT",
        "validity": "DAY",
        "securityId": str(row['SEM_SMST_SECURITY_ID']),
        "quantity": row['Buy Qty'],
        "disclosedQuantity": row['Buy Qty'],
        "price": row['price'],
        "triggerPrice": row['triggerPrice'],
        "price1": 0.0,
        "triggerPrice1": 0.0,
        "quantity1": 0
    }

    payload = json.dumps(order_data)

    headers = {
        'access-token': access_token,
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }

    # Send a POST request
    conn.request("POST", "/v2/forever/orders", payload, headers)

    res = conn.getresponse()
    data = res.read()

    # Print the response
    print(f"Order {index} response: {res.status} - {data.decode('utf-8')}")

i think these fields should not be included in payload.You already declared price once.

@Hardik please look into this

Hello @thiru

Can you keep disclosedQuantity as 0. Also, if you can send the JSON payload (not the python but actual request sent). This will help to debug faster.

hi @Hardik thanks for reply curl --request POST \ --url https://api.dhan.co/v2/forever/orders \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --header 'access-token: ' \ --data '{ "dhanClientId": "1101751259", "correlationId": "", "orderFlag": "SINGLE", "transactionType": "BUY", "exchangeSegment": "NSE_EQ", "productType": "MTF", "orderType": "LIMIT", "validity": "DAY", "securityId": "694", "quantity": 11.0, "disclosedQuantity": 0, "price": 1685.50, "triggerPrice": 1683.00, "price1": 0.0, "triggerPrice1": 0.0, "quantity1": 0.0 }' and this is the response { "errorType": "Order_Error", "errorCode": "DH-906", "errorMessage": "Missing required fields, bad values for parameters etc." }

@Hardik same works for CNC but not for MTF, kindly check.

Hello @thiru

Understood. Will try to replicate this and will get back to you.

Hello @thiru

Can you try now and confirm? We have made some changes at our end for the same.

Thank you for the effort @Hardik, but still same error, but the same works for CNC Forever order, "Order 0 response: 400 - {“errorType”:“Order_Error”,“errorCode”:“DH-906”,“errorMessage”:“Missing required fields, bad values for parameters etc.”}
"’

@Hardik any updates?

Hello @thiru

This has been fixed. Can you check once at your end?

@Hardik Thank you. Its Working Perfectly

1 Like

Hi @Hardik , if i change “orderType”: “LIMIT” to “orderType”: “MARKET”, in the same payload the order doesnt go through, do we need to make change in Price or Triggerprice , if we are placing a market order via forever order, can you check if the APIs are well handled for this case in backend, kindly help