Not able to place order

I am placing a sl order with these parameters

        res = api.place_order(security_id="59004", exchange_segment="NSE_FNO", transaction_type="SELL",
                    quantity=150, order_type="STOP_LOSS", product_type="INTRADAY", price=97.5, trigger_price=98 )

but keep getting error
{‘error_code’: ‘DH-906’, ‘error_type’: ‘Order_Error’, ‘error_message’: ‘Invalid Token’}

why is this happening, same code used to work before

@Hardik

Hey @Kush ,

We want to inform you that as per the Dhan library, to place an SL order, you need to follow the payload format below:

dhan.place_order(
    security_id='XXXXX',
    exchange_segment=dhan.NSE_FNO,
    transaction_type=dhan.SELL,
    quantity=150,
    order_type=dhan.SL,
    product_type=dhan.INTRA,
    trigger_price=10,
    price=9.50
)

For the complete request structures, please refer to:

We request you to also regenerate your access token before placing your orders.

We request you to also regenerate your access token before placing your orders.

code is placing sl orders automatically when a buy order is executed, and algo gets that info via order websocket, so that means my access token is correct.
I also verify my access token on startup before starting algo.

if you see the constants values in dhan python library, they are the same

class dhanhq(Order, ForeverOrder, Portfolio, Funds, Statement, TraderControl, Security,
             MarketFeed, HistoricalData, OptionChain):
    """DhanHQ Class having Core APIs"""

    """Constants for Exchange Segment"""
    NSE = 'NSE_EQ'
    BSE = 'BSE_EQ'
    CUR = 'NSE_CURRENCY'
    MCX = 'MCX_COMM'
    FNO = 'NSE_FNO'
    NSE_FNO = 'NSE_FNO'
    INTRA = "INTRADAY"
    SL = "STOP_LOSS"
    SELL = 'SELL'



and like i mentioned, code used to work earlier

@Trishul_Devadiga

Hi @Kush ,

We recommend testing the order placement using the payload provided by us to test the working.

Additionally, please drop an email to help@dhan.co from your registered email address so we can connect with you and assist further in resolving this.