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 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.
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
Could anyone from Zerodha team confirm whether it will be fixed? If not I have to find an alternative.
{\"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\"":""}}}
{"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\"}":""}}
I tried and it seems fine.
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
{"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\"":""}}}
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.
{ '{"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"': '' } }
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.
https://kite.trade/forum/discussion/comment/24282/#Comment_24282
Is there any way to test postback response post-market hours?
Rejected order: Getting rejected immediately through an exception
AMO order and cancel: These updates not coming to postback
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 propertytags
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 body3. Parsed this request to JSON
Hope this helps someone facing the same issue