Unable to place orders

sachin_jain3
When I am trying to place any orders for testing purpose I am getting this error, Can anyone help

Code line to place an order:
kite.place_order(variety="REGULAR", exchange="NSE", tradingsymbol="INFY", transaction_type="BUY", quantity="50", order_type="LIMIT", price="1400", product="NRML")

Error Got:
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/kiteconnect/connect.py", line 360, in place_order
return self._post("order.place",
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/kiteconnect/connect.py", line 855, in _post
return self._request(route, "POST", url_args=url_args, params=params, is_json=is_json, query_params=query_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/kiteconnect/connect.py", line 927, in _request
raise exp(data["message"], code=r.status_code)
kiteconnect.exceptions.InputException: Invalid `api_key` or `access_token`.

All other request using the same api_key, secret, access token and request token are working. i am able to query for the quote of NIFTY 50 like this :
nifty_quote = kite.quote('NSE:NIFTY 50')

But when placing orders its always failing whatever parameters i give. Is placing an order not allowed using the API? Is it a retailer thing only?
Tagged:
  • tonystark
    Could you post a minimal example code that can reproduce your problem at our end?

    Make sure to remove all account credentials from the code before posting.
  • sachin_jain3
    In the below code whether the gen_token is set to true or false (when the token was generated already) the last place_order call always results in exception: kiteconnect.exceptions.InputException: Invalid `api_key` or `access_token`. kite.quote calls always succeeds in both cases

    gen_token = True
    api_key = 'mykey'
    api_secret = 'mysecret'
    request_token = 'myrequesttoken'



    kite = KiteConnect(api_key=api_key)

    if gen_token:
    access_token = kite.generate_session(request_token, api_secret )['access_token']
    print("access token is " , access_token)
    else:
    access_token = "prev-access-token"

    kite.set_access_token(access_token)

    nifty_quote = kite.quote('NSE:NIFTY 50')
    print(nifty_quote)
    kite.place_order(variety="AMO", exchange="NSE", tradingsymbol="INFY", transaction_type="BUY", quantity="50", order_type="LIMIT", price="1300", product="NRML", validity="DAY")
  • rakeshr
    kite.place_order(variety="REGULAR",...
    You need to use small case letter for the variety field, here regular. Go through the order parameters documentation here.
  • sachin_jain3
    Thank you , that fixed my problem
This discussion has been closed.