Unable to place bracket order

Guhan

order_id = kite.order_place(
tradingsymbol="INFY",
exchange="NSE",
quantity=1,
transaction_type="BUY",
order_type="LIMIT",
price=1505,
squareoff_value=2,
stoploss_value=2,
variety="bo",
validity="DAY",
product = "MIS"
)

above code gives me below error:

Traceback (most recent call last):
File "C:/Python27/codes/pandas/summa.py", line 28, in
product = "MIS"
File "C:\Python27\lib\site-packages\kiteconnect\__init__.py", line 286, in order_place
return self._post("orders.place", params)["order_id"]
File "C:\Python27\lib\site-packages\kiteconnect\__init__.py", line 467, in _post
return self._request(route, "POST", params)
File "C:\Python27\lib\site-packages\kiteconnect\__init__.py", line 554, in _request
raise(exp(data["message"], code=r.status_code))
TokenException: Invalid token
  • sujith
    Hi @Guhan,
    It seems like your session is expired. Try logging in again and place order.
  • Guhan
    @sujith I tried again but it is not working.

    >>> from kiteconnect import KiteConnect
    >>> kite = KiteConnect(api_key =api_key)
    >>> kite.set_access_token(access_token)
    >>> kite.order_place(exchange = 'NSE', tradingsymbol = 'ASHOKLEY',
    transaction_type = 'BUY', quantity = 1,
    price = 105.05, product = 'MIS',
    order_type = 'LIMIT', squareoff_value = 1,
    stoploss_value = 1,trailing_stoploss = 1)#,variety ='bo',validity = 'DAY')
    u'170317000454573'

    >>> kite.order_place(exchange = 'NSE', tradingsymbol = 'ASHOKLEY',
    transaction_type = 'BUY', quantity = 1,
    price = 105.05, product = 'MIS',
    order_type = 'LIMIT', squareoff_value = 1,
    stoploss_value = 1,trailing_stoploss = 1,variety ='bo',validity = 'DAY')

    Traceback (most recent call last):
    File "", line 5, in
    stoploss_value = 1,trailing_stoploss = 1,variety ='bo',validity = 'DAY')
    File "C:\Python27\lib\site-packages\kiteconnect\__init__.py", line 286, in order_place
    return self._post("orders.place", params)["order_id"]
    File "C:\Python27\lib\site-packages\kiteconnect\__init__.py", line 467, in _post
    return self._request(route, "POST", params)
    File "C:\Python27\lib\site-packages\kiteconnect\__init__.py", line 554, in _request
    raise(exp(data["message"], code=r.status_code))
    TokenException: Invalid token
  • sujith
    @Guhan,
    Did you get new access token?
  • Guhan
    @sujith , thanks it is working fine. Can't I have PI running along with my API
  • Guhan
    @sujith I just wanna check how my coding works, because i see that whenever i log into PI my session gets expired
  • sujith
    @Guhan,
    Pi will create a new session every time you log in.
    Please use Kite and make sure you don't log out of Kite, that will delete your Kite Connect session also.
  • Guhan
    @sujith , oh ok, cheers
This discussion has been closed.