Am using pagekite instead of ngrok (to keep the URL) but all else is the same. However am getting only the string of two characters b" (i.e. letter b and a double quote char) returned. Same thing is being logged in the logfile also. Any suggestions on how I can fix this?
Yes, I am giving the correct postback URL, as am seeing the empty byte string on my server console. Is it possible that it send empty string in case of front-end initiated orders, and will send proper json string in case of orders sent programmatically? One of the FAQs seems to be saying that, though am not sure why that should be the case.
Also please help with these 2 further questions: (a) Kite Ticker is supposed to give order updates for subscribed tokens? I tried before and it also doesnt seem to be working. Any specific things to be done? (b) How do I test these postbacks and ticks callbacks afterhours?
@umasha
(a). You don't need to subscribe to a token for its order update via websocket. Did you define the on_order_update function and assign the callback ?? https://kite.trade/forum/discussion/5980/on-order-update-not-working
(b) You can't as orders are not accepted after market hours. Maybe,you can try amo. And for ticks,you will only recieve the last cached tick after market hours for any token.
@SRIJAN so how do we get a programmatic update (backend) for that first status for orders not from a program but user initiated from the front-end? IMHO, I feel there is no way for a program to paint a realistic picture of positions a trader has without that update (because even with an automated trading setup manual buy/sell orders are initiated all the time). We can cycle through kite.orders() list every second and get the diff from the previous second, but that is so clunky and not to mention that it will clash with the postback/callback setup. Please let me know how to resolve this.
Postbacks are only sent to the owner(origin platform) of the order. If user places order on your platform then only you will receive postback otherwise you won't get it. You need to use postback as an event to fetch orderbook and positions.
@umasha To know all the stages a order has gone through,you can save the order id. And call kite.order_history(order_id). Check structure of order history here: https://kite.trade/docs/connect/v3/orders/
I am coding a personal desktop system, so the owner is me myself. My ticker and webhook are not receiving the first update when I place a trade from sensibull. Are you saying that first postback is being eaten by sensibull?
This part is helpful - "You need to use postback as an event to fetch orderbook and positions." How do we do this when the event is not being triggered for that 1st COMPLETE status?
@umasha, Only sensibull will get the postback for the order that is placed on their platform. A third party app won't receive postback of the transaction done by client on some other app or kite web or kite app.
You may use websocket API order updates feature if you want to listen to order updates done by you on all the platforms. In this case as well, only client will receive the order update and not the third party app.
@SRIJAN Now am confused. I thought we were talking about Websocket API all along (through KiteTicker). Am using it, and am not receiving the 1st update. Is there some other Websocket API?
Look,I will make it clear.
1. For order updates,you can use either postback or on_order_update from websocket.
In both the cases,you won't get the first status of a order,if it's not sent from the api.
2. There is no way to get directly updated for the first order status. Still,if you want it, you have to use the order_id,and call order_history function. This will give you the complete history,all the stages the order has gone through until the time of request, and then check if your required status is in the response.
For #2, given that kiteticker or the webhook wont tell me what the new order_id is, the only way it to fetch orders list every second and compare with what's already there. Am I right?
My language may not show it, but am hugely appreciative of your patient handholding.
1. For order updates,you can use either postback or on_order_update from websocket. In both the cases,you won't get the first status of a order,if it's not sent from the api.
@SRIJAN There is slight difference in the order update behavior on postbacks and Websocket API. One can receive data about all the orders placed via websockets but postback API is called by Kite Connect only for the orders that are originated from the Kite Connect app.
For #2, given that kiteticker or the webhook wont tell me what the new order_id is, the only way it to fetch orders list every second and compare with what's already there. Am I right?
The place order API returns order id. You can fetch orderbook after a second and check the status of that order or fetch order history for the same.
@SRIJAN Beats me. Now I just put in 5 second loop that compares between kite.orders() and my DB, and just inserts what's missing (as we discussed). @sujith The problem I have is that order placement can happen through API, Zerodha front end or through a 3rd party app. I will have the order ID only in the 1st case.
I don't understand one thing. Why do you even need order id for orders not placed from api?? I mean if you place an order manually,what will you do with it programatically??
I reconstruct the position and adjustments to it based on order information to track position health. Certain info in an order doesnt get carried into a position, so I have to piece it together. Difficult to explain.
Have you added correct postback URL in the developers console?
Go through order postback FAQs here.
Yes, I am giving the correct postback URL, as am seeing the empty byte string on my server console. Is it possible that it send empty string in case of front-end initiated orders, and will send proper json string in case of orders sent programmatically? One of the FAQs seems to be saying that, though am not sure why that should be the case.
https://kite.trade/forum/discussion/6863/kiteconnect-postback-queries
(a). You don't need to subscribe to a token for its order update via websocket. Did you define the on_order_update function and assign the callback ?? https://kite.trade/forum/discussion/5980/on-order-update-not-working
(b) You can't as orders are not accepted after market hours. Maybe,you can try amo. And for ticks,you will only recieve the last cached tick after market hours for any token.
You need to use postback as an event to fetch orderbook and positions.
https://kite.trade/docs/connect/v3/orders/
This part is helpful - "You need to use postback as an event to fetch orderbook and positions." How do we do this when the event is not being triggered for that 1st COMPLETE status?
Only sensibull will get the postback for the order that is placed on their platform. A third party app won't receive postback of the transaction done by client on some other app or kite web or kite app.
You may use websocket API order updates feature if you want to listen to order updates done by you on all the platforms. In this case as well, only client will receive the order update and not the third party app.
1. For order updates,you can use either postback or on_order_update from websocket.
In both the cases,you won't get the first status of a order,if it's not sent from the api.
2. There is no way to get directly updated for the first order status. Still,if you want it, you have to use the order_id,and call order_history function. This will give you the complete history,all the stages the order has gone through until the time of request, and then check if your required status is in the response.
My language may not show it, but am hugely appreciative of your patient handholding.
One can receive data about all the orders placed via websockets but postback API is called by Kite Connect only for the orders that are originated from the Kite Connect app.
@sujith The problem I have is that order placement can happen through API, Zerodha front end or through a 3rd party app. I will have the order ID only in the 1st case.