Invalid API key or access key

LUCKYTRADE
Kite connect is active and can able to access historical data. But trade execution is giving error with" invalid appi key or access key."
Text files reading and writing keys correctly.

code:

logging.basicConfig(level=logging.DEBUG)
access = open(r"access_token.txt","r")
access_token=access.read()
access.close()
key = open(r"api_key.txt","r")
api_k=key.read()
key.close()

kite = KiteConnect(api_key=api_k)
kite.set_access_token(access_token)

try:
order = kite.place_order(exchange='NSE',
tradingsymbol='SBIN',
transaction_type="BUY",
quantity=1,
# price=price,
product='MIS',
order_type='MARKET',
validity='DAY',
# trigger_price='0',
# disclosed_quantity=None,
# squareoff=target,
# stoploss=stoploss_buy,
#trailing_stoploss=trailing_loss,
variety="Regular")
print(order)
except Exception as e:
print(e)
  • LUCKYTRADE
    @sujith please help me out
  • sujith
    You can run pykiteconnect in debug mode and check what are the params and auth headers you are sending.
  • LUCKYTRADE
    @sujith Thank you . Foundout the error...Resolved the issue. Thread can be closed.
    One more doubt. whether market order can be placed for banknifty option through kite API
  • rakeshr
    whether market order can be placed for banknifty option through kite API
    Yes, except for the illiquid index options contract. This article explains more about this.
This discussion has been closed.