place order using java and API

RH1558
RH1558 edited June 2016 in General
i write simple java code for place order using API, is below code is correct or wrong and how to place SL-M order

URL url = new URL("https://api.kite.trade/orders/regular");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setRequestProperty("api_key", "APIKEY");
conn.setRequestProperty("access_token", "AccessToken");
conn.setRequestProperty("tradingsymbol", "ABC");
conn.setRequestProperty("exchange","NSE");
conn.setRequestProperty("transaction_type","BUY");
conn.setRequestProperty("quantity","1");
conn.setRequestProperty("product","MIS");
conn.setRequestProperty("validity","DAY");

conn.setRequestProperty("trigger_price","XYZ.XY");
conn.setRequestProperty("squareoff_value","XYZ.XY"); //Bracket Order (BO)
conn.setRequestProperty("stoploss_value","XYZ.XY");//Bracket Order (BO)

Can anyone help me with place order,login user code ?
  • Kailash
    It looks correct, but you are placing a regular order, so the BO parameters won't work. If you want to place a BO, the request has to be POSTed to /orders/bo
  • RH1558
    RH1558 edited June 2016
    is following code correct for place BO order, and how to place SL-M order

    URL url = new URL("https://api.kite.trade/orders/bo");
    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
    conn.setRequestMethod("POST");
    conn.setDoInput(true);
    conn.setRequestProperty("api_key", "APIKEY");
    conn.setRequestProperty("access_token", "AccessToken");
    conn.setRequestProperty("tradingsymbol", "ABC");
    conn.setRequestProperty("exchange","NSE");
    conn.setRequestProperty("transaction_type","BUY");
    conn.setRequestProperty("quantity","1");
    conn.setRequestProperty("product","MIS");
    conn.setRequestProperty("validity","DAY");

    conn.setRequestProperty("trigger_price","XYZ.XY");
    conn.setRequestProperty("squareoff_value","XYZ.XY"); //Bracket Order (BO)
    conn.setRequestProperty("stoploss_value","XYZ.XY");//Bracket Order (BO)
  • rajeshreddyrr@gmail.com
    Hi RH, If possible , can you post complete JAVA code that includes Log-in mechanism
Sign In or Register to comment.