Postback api response seem broken

ramesh33
I am using Postback API to place stop-loss orders once my order gets filled. It was working fine till yesterday. But today payload in postback api response seem broken. Unable to parse to response to JSON.
  • ramesh33
    appreciate if anyone can confirm postback response is working/not working
  • ramesh33
    Ok. I have noticed this is broken because I have introduced tag property while placing the order. Postback response is fine without tag property.

    Could anyone from Zerodha team confirm whether it will be fixed? If not I have to find an alternative.
  • ramesh33
    Please find below the payload I got.

    {\"placed_by\":\"WZ**33\",\"order_id\":\"200427000396707\",\"exchange_order_id\":\"1100000000373349\",\"parent_order_id\":\"\",\"status\":\"COMPLETE\",\"status_message\":\"\",\"status_message_raw\":\"\",\"order_timestamp\":\"2020-04-27 09:21:17\",\"exchange_update_timestamp\":\"2020-04-27 09:21:17\",\"exchange_timestamp\":\"2020-04-27 09:20:06\",\"variety\":\"regular\",\"exchange\":\"NFO\",\"tradingsymbol\":\"NIFTY20APRFUT\",\"instrument_token\":14351106,\"order_type\":\"LIMIT\",\"transaction_type\":\"BUY\",\"validity\":\"DAY\",\"product\":\"MIS\",\"quantity\":75,\"disclosed_quantity\":0,\"price\":9286.8,\"trigger_price\":0,\"average_price\":9286.8,\"filled_quantity\":75,\"pending_quantity\":0,\"cancelled_quantity\":0,\"market_protection\":0,\"meta\":{},\"tag\":\"RAMCPI00L\",\"tags\":":{"\"RAMCPI00L\"":""}}}
  • sujith
    Can you let us know what is the error here?
  • ramesh33
    it's failing to parse this JSON
  • ramesh33
    Here is working one without passing tag

    {"body":{"{\"placed_by\":\"WZ**33\",\"order_id\":\"200427000552047\",\"exchange_order_id\":\"1000000002038995\",\"parent_order_id\":\"\",\"status\":\"COMPLETE\",\"status_message\":\"\",\"status_message_raw\":\"\",\"order_timestamp\":\"2020-04-27 09:23:49\",\"exchange_update_timestamp\":\"2020-04-27 09:23:49\",\"exchange_timestamp\":\"2020-04-27 09:23:49\",\"variety\":\"regular\",\"exchange\":\"NFO\",\"tradingsymbol\":\"NIFTY20APR9350CE\",\"instrument_token\":12164098,\"order_type\":\"MARKET\",\"transaction_type\":\"SELL\",\"validity\":\"DAY\",\"product\":\"MIS\",\"quantity\":75,\"disclosed_quantity\":0,\"price\":0,\"trigger_price\":0,\"average_price\":105.6,\"filled_quantity\":75,\"pending_quantity\":0,\"cancelled_quantity\":0,\"market_protection\":0,\"meta\":{},\"tag\":\"\",\"guid\":\"16141XsL5mHlmg1KrY\",\"user_id\":\"WZ4833\",\"unfilled_quantity\":0,\"app_id\":16141,\"checksum\":\"506088646ed3d1e02e8a15df98ad95f86f14f940b1d7c921077d415ba35a794f\"}":""}}
  • ramesh33
    Please let me know if it's still not clear.
  • sujith
    You can check out the postbacks format here.
    I tried and it seems fine.
  • ramesh33
    Hi Sujit,

    I have double-checked this. I am aware of the postback format and been using it for a while.

    Please try to parse postback JSON for an order with Tag.

    Thanks,
    Ramesh
  • ramesh33
    This is a fresh log from my server.

    {"body":{"{\"placed_by\":\"WZ**33\",\"order_id\":\"200427004540731\",\"exchange_order_id\":\"1000000030643963\",\"parent_order_id\":\"\",\"status\":\"COMPLETE\",\"status_message\":\"\",\"status_message_raw\":\"\",\"order_timestamp\":\"2020-04-27 13:40:18\",\"exchange_update_timestamp\":\"2020-04-27 13:40:18\",\"exchange_timestamp\":\"2020-04-27 13:40:18\",\"variety\":\"regular\",\"exchange\":\"NFO\",\"tradingsymbol\":\"NIFTY20APR9300PE\",\"instrument_token\":12163842,\"order_type\":\"MARKET\",\"transaction_type\":\"SELL\",\"validity\":\"DAY\",\"product\":\"MIS\",\"quantity\":75,\"disclosed_quantity\":0,\"price\":0,\"trigger_price\":0,\"average_price\":118.1,\"filled_quantity\":75,\"pending_quantity\":0,\"cancelled_quantity\":0,\"market_protection\":0,\"meta\":{},\"tag\":\"RAMISS00PE\",\"tags\":":{"\"RAMISS00PE\"":""}}}
  • ramesh33
    you can clearly see its broken after tags and missing remaining payload (unfilled_quantity, user_id, checksum etc.)
  • rakeshr
    @ramesh33
    We just checked at our end and postback is working fine.
    Postback_data b'{"placed_by":"XXXXXX","order_id":"XXXXXX","exchange_order_id":"","parent_order_id":"","status":"REJECTED","status_message":"XXXXXXXX","status_message_raw":"XXXXXX","order_timestamp":"2020-04-27 14:08:14","exchange_update_timestamp":"","exchange_timestamp":"","variety":"regular","exchange":"NSE","tradingsymbol":"SBICARD","instrument_token":4600577,"order_type":"LIMIT","transaction_type":"BUY","validity":"DAY","product":"CNC","quantity":1,"disclosed_quantity":0,"price":505,"trigger_price":0,"average_price":0,"filled_quantity":0,"pending_quantity":0,"cancelled_quantity":0,"market_protection":0,"meta":{},"tag":"BasketA","tags":["BasketA"],"guid":"7831XLXXXX","user_id":"XXXX","unfilled_quantity":0,"app_id":XXXX,"checksum":"c4805e24f0c99269a0eb02625c61f4b44bXXXXX"}'

    Can you re-check at your end, if you are parsing response properly? May be response length restriction,etc.
  • ramesh33
    No. It's still same for me. I tried again for the nth time. In your response tags are coming as array for you. For me, it's coming as an object.

    { '{"placed_by":"WZ**33","order_id":"200427005489994","exchange_order_id":"1000000041391151","parent_order_id":"","status":"COMPLETE","status_message":"","status_message_raw":"","order_timestamp":"2020-04-27 14:56:17","exchange_update_timestamp":"2020-04-27 14:56:17","exchange_timestamp":"2020-04-27 14:56:17","variety":"regular","exchange":"NFO","tradingsymbol":"NIFTY20APR9250PE","instrument_token":12163330,"order_type":"MARKET","transaction_type":"SELL","validity":"DAY","product":"MIS","quantity":75,"disclosed_quantity":0,"price":0,"trigger_price":0,"average_price":100.45,"filled_quantity":75,"pending_quantity":0,"cancelled_quantity":0,"market_protection":0,"meta":{},"tag":"RAMISS00PE","tags":': { '"RAMISS00PE"': '' } }
  • ramesh33
    Could you able to check the postback response sent for this ordereId at your end?

    I am using node+express for this. Don't think its anything to do with response length. But it's failing to parse tags array and breaking JSON.
  • ramesh33
    Just want to reiterate, Postback response JSON is fine without usiing tag while placing order. Its breaking only if I use tag
  • ramesh33
    I think I have to try the solution mentioned in this thread

    https://kite.trade/forum/discussion/comment/24282/#Comment_24282

    Is there any way to test postback response post-market hours?
  • sujith
    You can place an order which will get rejected or try placing amo.
  • ramesh33
    @sujith Both options didn't work.

    Rejected order: Getting rejected immediately through an exception
    AMO order and cancel: These updates not coming to postback
  • ramesh33
    Ok. Finally, I was able to resolve this issue. As mentioned in the above thread, Postback request’s content-type was set to application/x-www-form-urlencoded. This messed up my endpoint. I got carried away because the default parser worked fine without a tag in my order. There is an additional property tags which is of type Array getting added. My endpoint failed to parse this array field.

    It's supposed to content-type: JSON since the response is actually JSON. But not sure why it was not used.

    This is what I did.

    1. Ignore default parser and used the raw request body.
    2. Encoded response and stripped off : at the end of the req body
    3. Parsed this request to JSON

    Hope this helps someone facing the same issue
Sign In or Register to comment.