Modify Order: RS-9005 failure " todo mandatory fields '

I’m trying to modify a SL order.

dhan.modify_order(
                order_id=252305******,
                order_type=dhan.SL,
                leg_name='ENTRY_LEG',
                quantity=int(order_quantity),
                price=float(140.8),
                disclosed_quantity=int(order_quantity),
                trigger_price=float(135),
                validity=dhan.DAY
            )

It’s a FNO SL order. ‘leg_name’ is marked as conditionally required. But if I leave it off, I get the error that a positional field is missing. Same issue with ‘disclosed_quantity’. If I leave ‘leg_name’ as ‘’ (like in the example), I get the error that the field is blank. If I get any of the other value (like STOP_LOSS_LEG), I get the error code RS-9005 with message " todo mandatory fields ’ !! :roll_eyes: What does that even mean?

And more important, how do I modify an order. Using python.

1 Like

Hello @Sumith

Welcome to Dhan Community!

As in the example shared by you, leg_name should be ENTRY_LEG only if you want to add that. If you add this, what is the error message you are getting?

It will be great if you can share your Client ID along with API request time at api@dhan.co, so that we can look into from our end and help you resolve this faster.

Sent an email with the details. Thanks

Hi @Hardik , I never got a reply back after sending the email to api@dhan.co.

To your question after adding the leg_name as ENTRY_LEG, the error message is RS-9005 " todo mandatory fields ". What does this cryptic remark message mean? Someone forgot to finish their TODO items in the code?? There seems to be no way to modify an existing order contrary to what is in the API and examples. Any help will be appreciated.

Hello @Sumith

We checked the logs and found that the orders modifications were placed successfully. Have replied you on mail as well couple of days back for the same. In case you are still facing the issue, feel free to send in order ID on the same mail, and would definitely look into it.

Hello @Hardik

Order ID : 52240918873303
client_id : 1100475860

dhan.modify_order(
    order_id= pending_buy_orders[0],
    order_type=dhan.LIMIT,
    leg_name='ENTRY_LEG',
    quantity=15,
    price=200,
    disclosed_quantity=15,
    trigger_price=0,
    validity=dhan.DAY
)

This is the code that i am using to modify my entry leg of the order. The issue here is the modification is is working Limit orders, the same code is not working for modifying bracket orders. request you to please help me .

Hello @Sai_Chandra

If you look into the documentation, for BO order, you need to add order_type as dhan.BO.

Thank you @Hardik ,

I even tried that , no luck

@Sai_Chandra

Apologies. The order_type will dhan.LIMIT only. Can you keep disclosed quantity as 0 and check once again.

BINGO!

Thanks @Hardik. It works now.

Also @Hardik Now that am able to modify the price of the order, wanted to check if quantiy also can be modified ? as its not hapening…

Hello @Sai_Chandra

Yes, you can modify quantity also

Hello @Hardik

Can you please try from you end.

dhan.modify_order(
    order_id= pending_buy_orders[0],
    order_type=dhan.LIMIT,
    leg_name='ENTRY_LEG',
    quantity=45,
    price=58.70,
    disclosed_quantity=0,
    trigger_price=0,
    validity=dhan.DAY
)

I was able to place an order with 15 quantity, and was able to modify the price, but quantity is not being modified. can you please help me with this.

Hello @Hardik

Please find the below :handshake:

Although, there is no error with this code, but the order is not being modified. I mean price is being modified, but not the quantity. Could please re-look at this from your end.

Hello @Sai_Chandra

Are you changing both price and quantity in a single request or just one? Also, did you check wtih Get Order API to know the actual quantity post this?

Hello @Hardik ,

Yes i tried all permutations, tried modifying them seperately, together, nothing worked. I have also checked on order API, its the same - no modifications were seen.

All that am able to modify is the price, but not the quantity. Please check from your end if possible.

Hi @Hardik ,

Can you please address this issue at the earliest. Let me know if you need any further details.

Request you to try this from your end, just to verify you are able to modify the quantity from your end.

@Hardik I was inspired, by your video on webhooks, am absolute beginner at coding, have written this code using chat GPT,

the orders are being sent to exchange, but they are not exiting,

code
//@version=5
strategy(“2 - EMA NOT Working WEBHOOK”, overlay=true, shorttitle=“2”)

// Define input parameters
shortTermLength = input.int(2, title=“Short-Term EMA Length”, minval=1)
longTermLength = input.int(5, title=“Long-Term EMA Length”, minval=1)

stopLossPercent = input.float(1.5, title=“Stop Loss (%)”, step=0.1)
takeProfitPercent = input.float(3.0, title=“Take Profit (%)”, step=0.1)

startDate = input.time(timestamp(“2024-09-19 09:15”), title=“Start Date”)
endDate = input.time(timestamp(“2024-09-22 23:59”), title=“End Date”)

// Calculate EMAs
shortTermEMA = ta.ema(close, shortTermLength)
longTermEMA = ta.ema(close, longTermLength)

// Plot EMAs on the chart
plot(shortTermEMA, title=“Short-Term EMA”, color=color.blue, linewidth=2)
plot(longTermEMA, title=“Long-Term EMA”, color=color.red, linewidth=2)

// Check if current time is within the specified date range
inDateRange = (time >= startDate and time <= endDate)

// Define entry conditions
longCondition = inDateRange and ta.crossover(shortTermEMA, longTermEMA)
shortCondition = inDateRange and ta.crossunder(shortTermEMA, longTermEMA)

// Execute trades based on conditions
if (inDateRange)
if (longCondition)
strategy.entry(“Long”, strategy.long)
alert(“Long Entry Signal: Short-Term EMA crossed above Long-Term EMA”, alert.freq_once_per_bar_close)

if (strategy.position_size > 0)
stopLossLevel = strategy.position_avg_price * (1 - stopLossPercent / 100)
takeProfitLevel = strategy.position_avg_price * (1 + takeProfitPercent / 100)

// Set stop loss and take profit orders
strategy.exit("Exit Chotu", "Long", limit=takeProfitLevel, stop=stopLossLevel)

// Prepare JSON for webhook alert with dynamic stop loss and take profit prices
stopLossJson = '{"secret":"AQcgp","alertType":"multi_leg_order","order_legs":[{"transactionType":"B","orderType":"MKT","quantity":"1","exchange":"NSE","symbol":"CESC","instrument":"EQ","productType":"I","sort_order":"1","price":"0"},{"transactionType":"S","orderType":"SL","quantity":"1","exchange":"NSE","symbol":"CESC","instrument":"EQ","productType":"I","sort_order":"2","triggerPrice":"' + str.tostring(stopLossLevel) + '","price":"0"}]}'

takeProfitJson = '{"secret":"AQcgp","alertType":"multi_leg_order","order_legs":[{"transactionType":"B","orderType":"MKT","quantity":"1","exchange":"NSE","symbol":"CESC","instrument":"EQ","productType":"I","sort_order":"1","price":"0"},{"transactionType":"S","orderType":"SL","quantity":"1","exchange":"NSE","symbol":"CESC","instrument":"EQ","productType":"I","sort_order":"2","triggerPrice":"' + str.tostring(stopLossLevel) + '","price":"0"},{"transactionType":"S","orderType":"TP","quantity":"1","exchange":"NSE","symbol":"CESC","instrument":"EQ","productType":"I","sort_order":"3","triggerPrice":"' + str.tostring(takeProfitLevel) + '","price":"0"}]}'

// Trigger alerts for stop loss and take profit
if (close <= stopLossLevel)
    alert(stopLossJson, alert.freq_once_per_bar_close)

if (close >= takeProfitLevel)
    alert(takeProfitJson, alert.freq_once_per_bar_close)

json
{“secret”:“AQcgp”,“alertType”:“multi_leg_order”,“order_legs”:[{“transactionType”:“B”,“orderType”:“MKT”,“quantity”:“1”,“exchange”:“NSE”,“symbol”:“CESC”,“instrument”:“EQ”,“productType”:“I”,“sort_order”:“1”,“price”:“0”},{“transactionType”:“S”,“orderType”:“SL”,“quantity”:“1”,“exchange”:“NSE”,“symbol”:“CESC”,“instrument”:“EQ”,“productType”:“I”,“sort_order”:“2”,“triggerPrice”:“{{stopLossLevel}}”,“price”:“0”}]}

Sl 0.4% , take profit % .04

This is only for entering a position. You will have to write a similar message for
exit position as well if you wish to create separate conditions for exit.

kindly help what I am a doing wrong

Hi @Hardik

Did you get a chance to look into this please.

Hello @Sai_Chandra

Sorry I missed this earlier. BO order quantity cannot be modified in Version 1, as the earlier logic didn’t modify target and stop loss leg. This has been added with enhancement in V2.