com.zerodhatech.kiteconnect.kitehttp.exceptions.InputException for PlaceOrder

karthikt85
Hi Team,

I'm facing an input exception error when I'm trying to place the order using the JAVA method, I'm able to retrieve the quotes, order history etc. but not able to place the order. Following are my code snippet, logs with the values I'm seetting and the error message, can someone kindly help me with this.

Code Snippet:

public static String placeBO(KiteConnect kiteConnect, String transactionType, String symbol, String LTP, String entryLevel, String absoluteStopLoss, String absoluteTarget, String riskPerTrade, String bestBuyDepth, String bestSellDepth){

String orderId = "";
try{

OrderParams orderParams = new OrderParams();

//Set values for order type, symbol and tag
orderParams.transactionType = transactionType;
orderParams.exchange = symbol.split(":")[0];
orderParams.tradingsymbol = symbol.split(":")[1];
orderParams.orderType = "SL";
orderParams.validity = "day";
orderParams.product = "MIS";
orderParams.tag = "CustomTag";

System.out.println("Start Set Order Params");

//Set values for order quantity and price
orderParams.quantity = Integer.valueOf(calculateTradeQuantity(riskPerTrade, absoluteStopLoss));
orderParams.price = Double.valueOf(entryLevel);
orderParams.triggerPrice = Double.valueOf(calculateTriggerPrice(transactionType, entryLevel, bestBuyDepth, bestSellDepth));
orderParams.stoploss = Double.valueOf(absoluteStopLoss);
orderParams.squareoff = Double.valueOf(absoluteTarget);
orderParams.trailingStoploss = Double.valueOf(calculateTSLValue(LTP));

System.out.println("***** START TRADE LOG *****");
System.out.println("Transaction Type -> "+transactionType);
System.out.println("Exchange -> "+symbol.split(":")[0]);
System.out.println("Symbol -> "+symbol.split(":")[1]);
System.out.println("Quantity -> "+calculateTradeQuantity(riskPerTrade, absoluteStopLoss));
System.out.println("Entry Price -> "+Double.valueOf(entryLevel));
System.out.println("Trigger Price -> "+Double.valueOf(calculateTriggerPrice(transactionType, entryLevel, bestBuyDepth, bestSellDepth)));
System.out.println("Stop Loss -> "+Double.valueOf(absoluteStopLoss));
System.out.println("Square Of -> "+Double.valueOf(absoluteTarget));
System.out.println("TSL -> "+Double.valueOf(calculateTSLValue(LTP)));
System.out.println("***** END TRADE LOG *****");

System.out.println("Set Order Params");

Order order = kiteConnect.placeOrder(orderParams, "bo");
orderId = order.orderId;
}catch(Exception | KiteException e){
e.printStackTrace();;
}
return orderId;
}

Log message with values:

INFO | jvm 1 | 2019/02/19 11:54:29 | Start Set Order Params
INFO | jvm 1 | 2019/02/19 11:54:29 | ***** START TRADE LOG *****
INFO | jvm 1 | 2019/02/19 11:54:29 | Transaction Type -> BUY
INFO | jvm 1 | 2019/02/19 11:54:29 | Exchange -> NSE
INFO | jvm 1 | 2019/02/19 11:54:29 | Symbol -> ASHOKLEY
INFO | jvm 1 | 2019/02/19 11:54:29 | Quantity -> 63
INFO | jvm 1 | 2019/02/19 11:54:29 | Entry Price -> 80.45
INFO | jvm 1 | 2019/02/19 11:54:29 | Trigger Price -> 80.4
INFO | jvm 1 | 2019/02/19 11:54:29 | Stop Loss -> 0.4
INFO | jvm 1 | 2019/02/19 11:54:29 | Square Of -> 0.8
INFO | jvm 1 | 2019/02/19 11:54:29 | TSL -> 1.0
INFO | jvm 1 | 2019/02/19 11:54:29 | ***** END TRADE LOG *****
INFO | jvm 1 | 2019/02/19 11:54:29 | Set Order Params

Error message:

INFO | jvm 1 | 2019/02/19 11:49:24 | com.zerodhatech.kiteconnect.kitehttp.exceptions.InputException
INFO | jvm 1 | 2019/02/19 11:49:24 | at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.dealWithException(KiteResponseHandler.java:54)
INFO | jvm 1 | 2019/02/19 11:49:24 | at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.handle(KiteResponseHandler.java:20)
INFO | jvm 1 | 2019/02/19 11:49:24 | at com.zerodhatech.kiteconnect.kitehttp.KiteRequestHandler.postRequest(KiteRequestHandler.java:85)
INFO | jvm 1 | 2019/02/19 11:49:24 | at com.zerodhatech.kiteconnect.KiteConnect.placeOrder(KiteConnect.java:282)
  • sujith
    Can you paste the error message sent?
    Or just run it in debug mode to see the error message.
  • karthikt85
    @sujith

    Following is the error message I posted in the earlier post, not sure what you mean by "Can you paste the error message sent?"

    INFO | jvm 1 | 2019/02/19 11:49:24 | com.zerodhatech.kiteconnect.kitehttp.exceptions.InputException
    INFO | jvm 1 | 2019/02/19 11:49:24 | at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.dealWithException(KiteResponseHandler.java:54)
    INFO | jvm 1 | 2019/02/19 11:49:24 | at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.handle(KiteResponseHandler.java:20)
    INFO | jvm 1 | 2019/02/19 11:49:24 | at com.zerodhatech.kiteconnect.kitehttp.KiteRequestHandler.postRequest(KiteRequestHandler.java:85)
    INFO | jvm 1 | 2019/02/19 11:49:24 | at com.zerodhatech.kiteconnect.KiteConnect.placeOrder(KiteConnect.java:282)
  • sujith
    This is just the exception type. You can print the input exception message.
  • sujith
    A typical exception is something like this.
  • karthikt85
    karthikt85 edited February 2019
    @sujith

    I added an additional Catch block as follows and I got this message, not sure if this is because I was testing this at 4 AM, but this is the error I have now. Not sure what those single quotes are around the value, but

    INFO | jvm 1 | 2019/02/21 04:04:21 | Caught Input Exception -> Invalid `validity`
    //Method to place Bracket Order
    public static String placeBO(KiteConnect kiteConnect, String transactionType, String symbol, String LTP, String entryLevel, String absoluteStopLoss, String absoluteTarget, String riskPerTrade, String bestBuyDepth, String bestSellDepth){

    String orderId = "";
    try{

    OrderParams orderParams = new OrderParams();

    //Set values for order type, symbol and tag
    orderParams.transactionType = transactionType;
    orderParams.exchange = symbol.split(":")[0];
    orderParams.tradingsymbol = symbol.split(":")[1];
    orderParams.orderType = "SL";
    orderParams.validity = "day";
    orderParams.product = "MIS";
    orderParams.tag = "Elliot";
    System.out.println("Start Set Order Params");
    //Set values for order quantity and price
    orderParams.quantity = Integer.valueOf(calculateTradeQuantity(riskPerTrade, absoluteStopLoss));
    orderParams.price = Double.valueOf(entryLevel);
    orderParams.triggerPrice = Double.valueOf(calculateTriggerPrice(transactionType, entryLevel, bestBuyDepth, bestSellDepth));
    orderParams.stoploss = Double.valueOf(absoluteStopLoss);
    orderParams.squareoff = Double.valueOf(absoluteTarget);
    orderParams.trailingStoploss = Double.valueOf(calculateTSLValue(LTP));

    System.out.println("***** START TRADE LOG *****");
    System.out.println("Transaction Type -> "+transactionType);
    System.out.println("Exchange -> "+symbol.split(":")[0]);
    System.out.println("Symbol -> "+symbol.split(":")[1]);
    System.out.println("Quantity -> "+calculateTradeQuantity(riskPerTrade, absoluteStopLoss));
    System.out.println("Entry Price -> "+Double.valueOf(entryLevel));
    System.out.println("Trigger Price -> "+Double.valueOf(calculateTriggerPrice(transactionType, entryLevel, bestBuyDepth, bestSellDepth)));
    System.out.println("Stop Loss -> "+Double.valueOf(absoluteStopLoss));
    System.out.println("Square Of -> "+Double.valueOf(absoluteTarget));
    System.out.println("TSL -> "+Double.valueOf(calculateTSLValue(LTP)));
    System.out.println("***** END TRADE LOG *****");

    System.out.println("End Set Order Params");

    Order order = kiteConnect.placeOrder(orderParams, "bo");
    orderId = order.orderId;
    }catch(InputException e){
    System.out.println("Caught Input Exception -> "+e.message);
    }
    catch(KiteException | IOException e){

    e.printStackTrace();
    }
    return orderId;
    }
  • sujith
    You seem to be passing the wrong validity value. You need to send it in upper case, you can check out all constants here.
  • karthikt85
    Thanks a lot @sujith , I'm able to place the order via the API now :smile:
This discussion has been closed.