What is the api to close an open BUY position with MARKET price?

Hi All,

Can anyone pleas help me provide the correct syntax to close a BUY order with market price. I have tried below code and its giving error.

                resp = dhan.place_order(
                    tag='order',
                    transaction_type=dhan.SELL,
                    exchange_segment=dhan.NSE,
                    product_type=dhan.INTRA,
                    order_type=dhan.MARKET,
                    validity='DAY',
                    security_id=secid,
                    quantity=25,
                    disclosed_quantity=0,
                    price=0,
                    trigger_price=0,
                    after_market_order=False,
                    amo_time='OPEN',
                    bo_profit_value=0,
                    bo_stop_loss_Value=0,
                    drv_expiry_date=None,
                    drv_options_type=None,
                    drv_strike_price=None
                )

{‘status’: ‘failure’, ‘remarks’: {‘error_code’: ‘RS-9005’, ‘message’: ‘Transactions Fails.’}, ‘data’: ‘’}

Facing same issue. Please provide solution.

Hello @alok.nayak @SoAaDha1

In case you want to close a long position (Buy order), you can do so by placing a subsequent SELL order. You can keep all other fields same as the buy order with order_type as MARKET and transaction_type as SELL.

Can you help with the Security ID here, for which you are facing this issue.

@SoAaDha1 Welcome to Dhan Community too!