quote() Unable to get value

biswajit14
Hi,

I am using the following code:
#!python
from kiteconnect import KiteConnect

# Initialise.
kite = KiteConnect(api_key="your_api_key")

# Assuming you have obtained the `request_token`
# after the auth flow redirect by redirecting the
# user to kite.login_url()
try:
user = kite.request_access_token(request_token="obtained_request_token",
secret="your_api_secret")

kite.set_access_token(user["access_token"])
except Exception as e:
print("Authentication failed", str(e))
raise

print(user["user_id"], "has logged in")

# Get the list of positions.
print(kite.positions())
print(kite.quote("NSE", "INFY"))

Output:
I am able to get and get my positions, But the quote is giving error.

(u'XXXXXX', 'has logged in')
{u'net': [{u'day_sell_value': 0, u'day_buy_quantity': 0, u'last_price': 104, u'tradingsymbol':
Traceback (most recent call last):
File "C:\Users\Stocks\Z_Test.py", line 25, in
print(kite.quote("NSE", "INFY"))
File "C:\Python\lib\site-packages\kiteconnect-3.4.1-py2.7.egg\kiteconnect\__init__.py", line 404, in quote
File "C:\Python\lib\site-packages\kiteconnect-3.4.1-py2.7.egg\kiteconnect\__init__.py", line 463, in _get
File "C:\Python\lib\site-packages\kiteconnect-3.4.1-py2.7.egg\kiteconnect\__init__.py", line 554, in _request
kiteconnect.exceptions.TokenException: Invalid token

Please help me with this.
  • sujith
    sujith edited March 2017
    Hi @biswajit14,
    The request token is valid only for few minutes and you can use it only once. Hence it is recommended to make
    kite.request_access_token(request_token="obtained_request_token",
    secret=your_api_secret")
    this call only once.
    After you get the access token, store it and reuse it instead of requesting again.
Sign In or Register to comment.