Place order for option trade


  • ERROR

    a1= obj.placeOrder(orderparams)

    Traceback (most recent call last):

    File "<ipython-input-24-e4e648b3ffb3>", line 1, in <module>
    a1= obj.placeOrder(orderparams)

    File "C:\Users\nikma\Anaconda3\lib\site-packages\smartapi\smartConnect.py", line 290, in placeOrder
    orderResponse= self._postRequest("api.order.place", params)['data']['orderid']

    TypeError: 'NoneType' object is not subscriptable

    params

    {'variety': 'NORMAL',
    'tradingsymbol': 'RELIANCE29DEC222440PE',
    'symboltoken': '142072',
    'transactiontype': 'SELL',
    'exchange': 'NFO',
    'ordertype': 'MARKET',
    'producttype': 'CARRYFORWARD',
    'duration': 'DAY',
    'quantity': '1250',
    'ordertag': 'strangle'}


  • Hi @nickmanan

    We have noticed that you are experiencing issues with our SDK due to poor error handling. The error message you are seeing, "TypeError: 'NoneType' object is not subscriptable", is a result of the SDK not handling exceptions properly. This is causing the orderResponse variable to be None, which is leading to the error you are seeing.

    The correct error message from the RestAPI is "Invalid Session or Session is Expired Please Re-login" with error code "AB1010". This error is likely being caused because you are using an expired JWT token. (Read more about it here - https://smartapi.angelbroking.com/topic/3392/faqs-on-ab1010-invalid-session-or-session-expired-please-re-login?_=1671130890317)

    Please note that our SDKs are open source, so you are welcome to make contributions to improve the error handling and other aspects of the code. Additionally, if you encounter any errors in the future, you can make a call to the RestAPI directly to get the correct error message and information on how to resolve the issue.

    We apologize for any inconvenience this may have caused and thank you for your understanding.