Getting Invalid instrument error ..

vigneswaranj
Hello ,

getting below error while placing gtt order , checked the instrument from the csv file , it seems fine ..
onnect\connect.py", line 927, in _request
raise exp(data["message"], code=r.status_code)
kiteconnect.exceptions.InputException: Invalid instrument

-------------------------------------------------------------------------------------------------------------------------
orders = [
{
"exchange": "NFO",
"tradingsymbol": "NIFTY23SEP19000PE",
"transaction_type": kite.TRANSACTION_TYPE_SELL,
"quantity": 50,
"order_type": "LIMIT",
"product": "PRODUCT_MIS",
"price": 4.50,
},
{
"exchange": "NFO",
"tradingsymbol": "NIFTY23SEP19000PE",
"transaction_type": kite.TRANSACTION_TYPE_SELL,
"quantity": 50,
"order_type": "LIMIT",
"product": "PRODUCT_MIS",
"price": 4.60,
},
]

gtt_oco = kite.place_gtt(
trigger_type=kite.GTT_TYPE_OCO,
tradingsymbol="NIFTY23SEP19000PE",
exchange="NSE",
trigger_values=[4.50, 4.60],
last_price=4.40,
orders=orders,
)

if gtt_oco["status"] == "success":
print("GTT order placed successfully.")
else:
print("GTT order placement failed: {}".format(gtt_oco["message"]))
  • sujith
    Can you enable debug logs and paste the complete stacktrace here? Need to see the complete request and response logs to evaluate further.

    PS: Make sure to remove app and client specific tokens.
  • vigneswaranj
    rs\vigne\.vscode\extensions\ms-python.python-2023.16.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '58892' '--' 'D:\Shares\Python\GUI_Start\New_22_Sep_23\GTT_Order_Failed..py'
    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
    DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "POST /gtt/triggers HTTP/1.1" 400 91

    this what i got after enabling logs ..

    "logging.basicConfig(level=logging.DEBUG)"

    Is there another way to enable more detailed logs ??
  • vigneswaranj
    I was able to fetch more details , hope this will be helpful ..

    .\debugpy\launcher' '59713' '--' 'D:\Shares\Python\GUI_Start\New_22_Sep_23\GTT_Order_Failed..py'
    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
    send: b'POST /gtt/triggers HTTP/1.1\r\nHost: api.kite.trade\r\nUser-Agent: Kiteconnect-python/4.2.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nX-Kite-Version: 3\r\nAuthorization: token knk9kc:eXn347Ab\r\nContent-Length: 661\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n'
    send: b'condition=%7B%22exchange%22%3A+%22NSE%22%2C+%22tradingsymbol%22%3A+%22NIFTY23SEP19000PE%22%2C+%22trigger_values%22%3A+%5B4.5%2C+4.6%5D%2C+%22last_price%22%3A+4.4%7D&orders=%5B%7B%22exchange%22%3A+%22NSE%22%2C+%22tradingsymbol%22%3A+%22NIFTY23SEP19000PE%22%2C+%22transaction_type%22%3A+%22SELL%22%2C+%22quantity%22%3A+1%2C+%22order_type%22%3A+%22LIMIT%22%2C+%22product%22%3A+%22MIS%22%2C+%22price%22%3A+4.5%7D%2C+%7B%22exchange%22%3A+%22NSE%22%2C+%22tradingsymbol%22%3A+%22NIFTY23SEP19000PE%22%2C+%22transaction_type%22%3A+%22SELL%22%2C+%22quantity%22%3A+1%2C+%22order_type%22%3A+%22LIMIT%22%2C+%22product%22%3A+%22MIS%22%2C+%22price%22%3A+4.6%7D%5D&type=two-leg'
    reply: 'HTTP/1.1 400 Bad Request\r\n'
    header: Date: Fri, 22 Sep 2023 08:44:59 GMT
    header: Content-Type: application/json
    header: Content-Length: 91
    header: Connection: keep-alive
    header: CF-Cache-Status: DYNAMIC
    header: Strict-Transport-Security: max-age=15552000; includeSubDomains
    header: Set-Cookie: _cfuvid=UqKvZ1nfuTC78LlVIOkegldcb70XyfOcWfZQFBt_hC8-1695372299732-0-604800000; path=/; domain=.kite.trade; HttpOnly; Secure; SameSite=None
    header: Server: cloudflare
    header: CF-RAY: 80a944e8ca619ff1-SIN
    header: alt-svc: h3=":443"; ma=86400
    DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "POST /gtt/triggers HTTP/1.1" 400 91
    An error occurred: Invalid instrument
    PS D:\Shares\Python>
  • vigneswaranj
    the same command working fine for stock , but not working for options ..



    Also in the logs i see , even if i have mentioned exchange": "NFO in the request , while sending it to kite , somehow it changed to NSE ...

    send: b'condition=%7B%22exchange%22%3A+%22NSE%22%2C+
    GTT.png 36.2K
  • rakeshr
    tradingsymbol="NIFTY23SEP19000PE",
    exchange="NSE",
    You need to use exchange as NFO, in the gtt order params.
  • vigneswaranj
    thanks for the response , it's working now ...
This discussion has been closed.