PHP KiteConnect : How to code POST BACK page?

sachinstlko09
Hi,
If one MIS Buy order is placed of some price. Now, I want to place another MIS order Buy or Sell depend on the calculated price at the Post Back Page.
Please share some sample code or idea.
  • sachinstlko09
    Any one please suggest??
  • sachinstlko09
    Need suggestion?
  • botany02
    botany02 edited October 2017
  • botany02
    botany02 edited October 2017
    @sachinstlko09
    You may try the below

    <?php
    /*See whether the request is POST or not
    if the request is not POST then exit
    you may echo any custom message or throw exception to debug
    or you can just exit the code*/

    if ($_SERVER['REQUEST_METHOD'] !== 'POST')
    {
    echo "POST Method Expected";
    return;
    }

    /*we will read the POST body and store it in a variable*/
    $postdata = file_get_contents("php://input");
    /*next we will decode the json message body*/
    $json_o = json_decode($postdata);
    /*retrieve the order number and save the json response with orderid as name for future use*/
    $orderid = $json_o->order_id;
    $log_file = $orderid . '.json';
    file_put_contents($log_file, $postdata);
    /*retrieve other properties from the json*/
    /*Trade Symbol*/
    $trdsym = $json_o->tradingsymbol;
    /*status*/
    $status = $json_o->status;
    /*filled price*/
    $filledprice = $json_o->average_price;
    /*filled qty*/
    $filledqty = $json_o->filled_quantity;
    /*and so on*/
    /*now you got the order details.manipulate whatever you want*/
    /*final step.echo success*/
    echo "Success";
    /*Sample Pay load from kite server
    {
    "order_id": "16032300017157",
    "exchange_order_id": "511220371736111",
    "placed_by": "AB0012",
    "status": "COMPLETE",
    "status_message": "",

    "tradingsymbol": "TATAMOTORS",
    "exchange": "NSE",
    "order_type": "MARKET",
    "transaction_type": "SELL",
    "validity": "DAY",
    "product": "CNC",

    "average_price": 376.35,
    "price": 376.35,
    "quantity": 1,
    "filled_quantity": 1,
    "unfilled_quantity": 0,
    "trigger_price": 0,
    "status_message": "",
    "user_id": "AB0012",
    "order_timestamp": "2015-12-20 15:01:43",
    "exchange_timestamp": "2015-12-20 15:01:43",
    "checksum": "5aa3f8e3c8cc41cff362de9f73212e28"
    }

    You can just use the above sample payload at https://www.hurl.it to check
    or debug or test your code.
    Remember you need to post the payload as body.
    You can create a subdomain like https://kite.yourdoamin.in
    and save this php file as index.php
    */
    ?>
  • sachinstlko09
    @botany02 I was using given provided code, But I can not properly use it.
    I can not see any response back on this page. Even without any condition, I am trying to put BO, but order is also not successfully placed.
Sign In or Register to comment.