zerodha / pykiteconnect

The official Python client library for the Kite Connect trading APIs
MIT License
981 stars 469 forks source link

GTT order placement returns invalid api_key error #74

Closed ajaipaulose closed 2 years ago

ajaipaulose commented 4 years ago

I tried the following command for placig a GTT order

curl https://api.kite.trade/gtt/triggers \ -H 'X-Kite-Version: 3' \ -H 'Authorization: token api_key:xxxxxxxxxxxxxxxxxxxxxxxxxx' \ -d 'type=single' \ -d 'condition={"exchange":"NSE", "tradingsymbol":"INFY", "trigger_values":[702.0], "last_price": 798.0}' \ -d 'orders=[{"exchange":"NSE", "tradingsymbol": "INFY", "transaction_type": "BUY", "quantity": 1, "order_type": "LIMIT","product": "CNC", "price": 702.5}]'

It returns the following error {"status":"error","message":"Incorrectapi_keyoraccess_token.","data":null,"error_type":"TokenException"}

I am sure api_key is correct as the following command is working

curl "https://api.kite.trade/instruments" \ -H "X-Kite-Version: 3" \ -H "Authorization: token api_key:xxxxxxxxxxxxxx"

What is wrong with the gtt command?

ranjanrak commented 2 years ago

-H "Authorization: token api_key:xxxxxxxxxxxxxx"

You need to send access_token as well in auth header. The correct format would be : -H 'Authorization: token {your_api_key}:{access_token}' Go through the documentation here.