Input exception when placing buy order

AkashRam
Code -
for token in option_data:
if token in int_token and token in option_buy and token not in tokens_to_remove:
if option_data[token] > option_buy[token]:
ts = token_symbol_map[token]
b_qty = getBuyingQuantity(ts)
print(f"Trading symbol : {ts}")
print(f"Quantity to buy : {b_qty}")

b_order_id = kite.place_order(tradingsymbol=ts,
exchange=returnExchange(), # returnexchange(),
transaction_type="BUY",
variety='regular',
quantity=b_qty,
order_type='MARKET',
product='NRML')

Response -
Trading symbol : MIDCPNIFTY2461412025CE
Quantity to buy : 75
Traceback (most recent call last):
File "/Users/akashram/PycharmProjects/Zerodha Algo/main.py", line 971, in
b_order_id = kite.place_order(tradingsymbol=ts,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/akashram/PycharmProjects/Zerodha Algo/.venv/lib/python3.12/site-packages/kiteconnect/connect.py", line 361, in place_order
return self._post("order.place",
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/akashram/PycharmProjects/Zerodha Algo/.venv/lib/python3.12/site-packages/kiteconnect/connect.py", line 865, in _post
return self._request(route, "POST", url_args=url_args, params=params, is_json=is_json, query_params=query_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/akashram/PycharmProjects/Zerodha Algo/.venv/lib/python3.12/site-packages/kiteconnect/connect.py", line 937, in _request
raise exp(data["message"], code=r.status_code)
kiteconnect.exceptions.InputException: The instrument you are placing an order for has either expired or does not exist.

Any help would be appreciated, thanks!
  • sujith
    Can you run with debug logs on and paste the request and response json?

    PS: Make sure to remove app and client specific tokens
  • AkashRam
    Thanks for the response Sujith, will do so now, is the trading symbol format [Trading symbol : MIDCPNIFTY2461412025CE] correct? Thanks.
  • sujith
    You can fetch the instruments master file and check if this entry exists.
  • AkashRam
    Thanks for the response @sujith, here is the debug logs -

    Trading symbol : SENSEX2462177200PE
    Quantity to buy : 20
    DEBUG:kiteconnect.connect:Request: POST https://api.kite.trade/orders/regular {'variety': 'regular', 'exchange': 'NFO', 'tradingsymbol': 'SENSEX2462177200PE', 'transaction_type': 'BUY', 'quantity': 20, 'product': 'NRML', 'order_type': 'MARKET'} {'X-Kite-Version': '3', 'User-Agent': 'Kiteconnect-python/5.0.0', 'Authorization': '----------------'}
    DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "POST /orders/regular HTTP/1.1" 400 154
    DEBUG:kiteconnect.connect:Response: 400 b'{"status":"error","message":"The instrument you are placing an order for has either expired or does not exist.","data":null,"error_type":"InputException"}'
    Traceback (most recent call last):
    File "/Users/akashram/PycharmProjects/Zerodha Algo/main.py", line 973, in
    b_order_id = kite.place_order(tradingsymbol=ts,
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Users/akashram/PycharmProjects/Zerodha Algo/.venv/lib/python3.12/site-packages/kiteconnect/connect.py", line 361, in place_order
    return self._post("order.place",
    ^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Users/akashram/PycharmProjects/Zerodha Algo/.venv/lib/python3.12/site-packages/kiteconnect/connect.py", line 865, in _post
    return self._request(route, "POST", url_args=url_args, params=params, is_json=is_json, query_params=query_params)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Users/akashram/PycharmProjects/Zerodha Algo/.venv/lib/python3.12/site-packages/kiteconnect/connect.py", line 937, in _request
    raise exp(data["message"], code=r.status_code)
    kiteconnect.exceptions.InputException: The instrument you are placing an order for has either expired or does not exist.
  • AkashRam
    The post request was successful for Nifty and BN, but seems to be failing for Sensex? Any help would be appreciated, thank you!
  • AkashRam
    Hey Sujith, found out the issue, exchange was NFO instead of BFO, you can close the thread.
This discussion has been closed.