Error while placing order via kiteConnect using place_order API

Sonia
@Nivas I got below error while placing order this is the request body I am constructing while reading from excel exchange tradingsymbol transaction_type order_type quantity product validity price trigger_price
NSE RVHL BUY Limit 10 Delivery DAY 50 50.3 exchange tradingsymbol instrument_token
565 NSE RVHL 400641
Error placing order for RVHL: Invalid request (failed to decode `trigger_price`, got: `nan` (expected decimal))

Can you please kindly help me on this?
  • Nivas
    This usually happens when your code sends the data as "nan" in the API request. You would've to update your code to send the correct trigger_price.
  • Sonia
    I fixed that @Nivas Now this is new error and I have changed the stock symbol but not luck .. RVHL: The instrument you are placing an order for has either expired or does not exist. this is my correct code now kite = KiteConnect(api_key=api_key)
    kite.set_access_token(access_token)

    # Read Excel orders
    df = pd.read_csv("orders.txt",sep=",")
    print("RAW columns:", df.columns.tolist())
    print("\n")
    df.columns = df.columns.str.strip()
    print("STRIPPED columns:", df.columns.tolist())
    # df['exchange'] = df['exchange'].str.strip().str.upper()
    # df['tradingsymbol'] = df['tradingsymbol'].str.strip().str.upper()
    df["price"] = pd.to_numeric(df["price"], errors="coerce")
    df["trigger_price"] = pd.to_numeric(df.get("trigger_price", []), errors="coerce")

    # — Verify symbol
    inst = kite.instruments("NSE")
    df_inst = pd.DataFrame(inst)
    print("RVHL Details",df_inst[df_inst.tradingsymbol == "RVHL"][["exchange","tradingsymbol","instrument_token"]])
    print("Exact symbol","\n", df_inst[df_inst['tradingsymbol'] == "RVHL"][["exchange", "tradingsymbol"]])

    for _, row in df.iterrows():
    try:
    params = {
    "variety": kite.VARIETY_REGULAR,
    "exchange": row["exchange"],
    "tradingsymbol": row["tradingsymbol"],
    "transaction_type": row["transaction_type"],
    "quantity": int(row["quantity"]),
    "order_type": row["order_type"],
    "product": row["product"],
    "validity": row["validity"],
    "price": row["price"],
    "trigger_price": row["trigger_price"]
    }
    # Only add price if it’s not NaN
    if not pd.isna(row["price"]):
    params["price"] = float(row["price"])

    # Likewise, for trigger_price if you have it
    if "trigger_price" in row and not pd.isna(row["trigger_price"]):
    params["trigger_price"] = float(row["trigger_price"])

    order_id = kite.place_order(**params)
    print(f"Order placed. ID: {order_id}")

    except Exception as e:
    print(f"Error placing order for {row['tradingsymbol']}: {e}")
  • Sonia
    @Nivas Many Thanks for helping me I was able to place an order. Lovely thanks!
This discussion has been closed.