After getting the request token after the login flow I am using this code to get the access token . But the code says Invalid session credentials . Where I am wrong ?
kite = KiteConnect(api_key="xxxxxx ") #print(kite.login_url()) data = kite.request_access_token(request_token="zzzzzz",secret="yyyyyy") kite.set_access_token(data["access_token"])
# Place an order try: order_id = kite.order_place(tradingsymbol="INFY", exchange="NSE", transaction_type="BUY", quantity=1, order_type="MARKET", product="NRML")
print("Order placed. ID is", order_id) except Exception as e: print("Order placement failed", e.message)
@beast123, Things that you need to check, if you have this error. 1. You should access API for same user with which you have registered app. 2. Request token is valid for only 5 minutes, make sure you use it before it expires. 3. Request token can be used only once, so make sure you don't call "request_access_token" API every time you run app. Once you get access token, store it and use it next time you run app.
Hi @beast123, Your login code is fine, but in place order method params, you should send "CNC" as product not "NRML". You should include "validity" as "DAY" also. You can checkout more examples here. But this has nothing to do with error thrown i.e. invalid credentials.
PS: For equity product can be "CNC"(delivery) or "MIS"(intraday) whereas for futures, options, currency and commodity product can be "NRML" or "MIS".
I was able to print the url generated by the api . After that I opened the link in the browser and got the request token from the redirect url. Then I copied it and pasted it in the line above then it is giving me error . I just need to get format of the method above !
Things that you need to check, if you have this error.
1. You should access API for same user with which you have registered app.
2. Request token is valid for only 5 minutes, make sure you use it before it expires.
3. Request token can be used only once, so make sure you don't call "request_access_token" API every time you run app. Once you get access token, store it and use it next time you run app.
Can you please check ?
its in python
data = kite.request_access_token(request_token="zzzzzz",secret="yyyyyy")
Your login code is fine, but in place order method params, you should send "CNC" as product not "NRML". You should include "validity" as "DAY" also. You can checkout more examples here.
But this has nothing to do with error thrown i.e. invalid credentials.
PS: For equity product can be "CNC"(delivery) or "MIS"(intraday) whereas for futures, options, currency and commodity product can be "NRML" or "MIS".
Because of this line I am getting an error ...It says invelid session credentials
data = kite.request_access_token(request_token="zzzzzz",secret="yyyyyy")
It is because, request token can be used only once.
You were able to access API on first run after giving new request token?
Can you private message your api_key?