Stop loss to existing trades using dhan api

How can we apply stop loss to existing running trades and modify them while trailing?

Hello @paritosh176

Welcome to MadeForTrade community!

You can add SL orders via API, and modify the same. Alternatively, you can also place Cover Orders for this.

1 Like

Hello @Hardik

I am facing issues while modifying an order , can you please correct me where am i going wrong…

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

Hello @Sai_Chandra

Can you tell me which field are you modifying and what is the initial order?

Hello @Hardik ,

Thanks for getting back, i have place a bracket order (#52240918873303) ,

entry price = 279.
order status = pending
CMP = 400 (FYI)

My plan to modify the entry leg to change the entry price 300.

error:
{‘status’: ‘failure’,
‘remarks’: {‘error_code’: ‘RS-9005’, ‘message’: ’ todo mandatory fields '},
‘data’: ‘’}

Code used to place order:

dhan.place_order(
                        tag='SAI',
                        security_id=44993,
                        exchange_segment=dhan.FNO,
                        transaction_type=dhan.BUY,
                        quantity=15,
                        order_type=dhan.LIMIT,
                        product_type=dhan.BO ,
                        price= 279,
                        bo_profit_value=30,
                        bo_stop_loss_Value=10,
                    )

Code used to modify the order:

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
)

The code used to modify the order works seemlessly , while modifying the existing limit order, however the same code throws an error while modifying bracket orders.

Please let me know , if you need any further details. I have also sent an email mentioning this issue on api@dhan.co.

1 Like

Hello @Sai_Chandra

Kindly avoid opening multiple threads for same issue. I have replied to your query here: Modify Order: RS-9005 failure " todo mandatory fields ' - #7 by Hardik

Apologies for the inconvinence @Hardik , Am new to this platform… am learning where to type my queries… shall be mindful going forward.

Thanks for understanding.

1 Like