Hi Team, Today I cloned Kite3 branch and started working on it. I am getting few exceptions on placing orders and I'm unable to detect the source of these errors clearly. Below is the error trace. @sujith@Vivek Please help!
@sujith is this accesstoken based authentication something new,going live with kite3? or this is something which is already in production?please tell what new to do?
@sujith I am generating access token the same way I did earlier for the code that I cloned from the master build, and I've used same old URL. So here are my steps: 1.) Using api key, get request token info from the redirect url 2.) Use request token and api secret key to get access token 3.) Use access token for placing/modifying/canceling orders
@cisk, Are you trying to use Kite Ticker for order updates? Can you paste the URL you are trying to connect?
PS: You need to be connected in order to receive order updates. If you open websocket connection after placing the order, it more likely that you would have missed that order update.
@rayi, It is already live, you can check out the example in the kite3 branch of repository.
For tick updates: kws = KiteTicker("vot80c34vmxpihm", "4Lkezddj7RcRCnHqRSbqe2KCsuaIzf65", "YM3440", debug=True)
For placing an order: self.kite = KiteConnect(api_key="vot80c34vmxpihm", debug=True, timeout=7) self.kite.set_access_token("4Lkezddj7RcRCnHqRSbqe2KCsuaIzf65")
My intention is to place an order based on some logic under on_tick method and then monitor the order updates using on_message callback of the already created KiteTicker object creater earlier. I hope I am doing it correctly!
P.S: 1. I am creating KiteTicker object first and then placing orders on verifying some condition under the method def on_tick(tick, ws): ...... pass 2. Api key, access token and user id have been modified here.
@tonystark The issue was related to subscribing 200 instruments. The error message was not intuitive at all! @sujit I am trying to read order status from websockets but I'm unable to do so using on_message callbacks. Can you please upload the GIT repo with on_message examples? I can't seem to figure it out easily
What all do we need to set for the function and how to read the return values is very unclear. Please help
def on_message(ws, payload, is_binary): # if ws.on_message: # ws.on_message(ws, payload, is_binary) # # # If the message is binary, parse it and send it to the callback. # if ws.on_ticks and is_binary and len(payload) > 4: # ws.on_ticks(ws, ws._parse_binary(payload)) # # # Parse text messages if not is_binary: print("Message arrived", ws._parse_text_message(payload))
@sujith Thank you. I'll check this tomorrow. Few follow up questions: 1. How can I know possible states for on_order_update (link for document) 2. How is on_order_update different from on_message
on_message is not only meant for order updates. There are many other platform text messages. You need to listen to only order updates and ignore the rest.
@sujith Thanks for the info. I checked the order updated and got update for few events but not all. Here are my doubts: 1. I modified order from Kite web browser but that event was not logged in my _on_order_update method 2. I created a websocket in a seperate thread, but Order Placing(CONFIRMED) was not logged. Why so? 3. I do not understand why multiple loggings are observed for cancellation event, only pending_quantity is changed. 4. I could capture logs for order fill and cancel but not for confirmation and modification
I have attached the logs for inspection. Few details of mine have been modified
@cisk 1. We are already looking into this. It will be fixed shortly. 2. When you place an order and you get back an ID then it is confirmed. There is no confirmation update through WebSocket. 3. This is a long-standing issue from OMS. We have contacted them to fix this.
Today I cloned Kite3 branch and started working on it. I am getting few exceptions on placing orders and I'm unable to detect the source of these errors clearly. Below is the error trace. @sujith @Vivek Please help!
2018-01-15 16:28:47+0530 [-] failing WebSocket opening handshake ('WebSocket connection upgrade failed (400 - BadRequest)')
2018-01-15 16:28:47,789 ERROR 188 kiteconnect.ticker WebSocket connection lost: [Failure instance: Traceback (failure with no frames): : Connection was aborted locally, using.
2018-01-15 16:28:47+0530 [-] dropping connection to peer tcp4:35.154.90.24:443 with abort=True: WebSocket connection upgrade failed (400 - BadRequest)
].
2018-01-15 16:28:47+0530 [-] will retry in 2 seconds
2018-01-15 16:28:47+0530 [-] Stopping factory
2018-01-15 16:28:50+0530 [-] Starting factory
1.) Using api key, get request token info from the redirect url
2.) Use request token and api secret key to get access token
3.) Use access token for placing/modifying/canceling orders
Are you trying to use Kite Ticker for order updates?
Can you paste the URL you are trying to connect?
PS: You need to be connected in order to receive order updates. If you open websocket connection after placing the order, it more likely that you would have missed that order update.
@rayi,
It is already live, you can check out the example in the kite3 branch of repository.
For tick updates:
kws = KiteTicker("vot80c34vmxpihm", "4Lkezddj7RcRCnHqRSbqe2KCsuaIzf65", "YM3440", debug=True)
For placing an order:
self.kite = KiteConnect(api_key="vot80c34vmxpihm", debug=True, timeout=7)
self.kite.set_access_token("4Lkezddj7RcRCnHqRSbqe2KCsuaIzf65")
My intention is to place an order based on some logic under on_tick method and then monitor the order updates using on_message callback of the already created KiteTicker object creater earlier. I hope I am doing it correctly!
P.S:
1. I am creating KiteTicker object first and then placing orders on verifying some condition under the method
def on_tick(tick, ws):
......
pass
2. Api key, access token and user id have been modified here.
2018-01-16 10:56:51+0530 [KiteTickerClientProtocol (TLSMemoryBIOProtocol),client] will retry in 2 seconds
2018-01-16 10:56:51,712 ERROR 188 kiteconnect.ticker WebSocket connection lost: [Failure instance: Traceback (failure with no frames): : Connection was closed cleanly.
2018-01-16 10:56:51+0530 [-] Stopping factory
].
@sujit I am trying to read order status from websockets but I'm unable to do so using on_message callbacks. Can you please upload the GIT repo with on_message examples? I can't seem to figure it out easily
What all do we need to set for the function and how to read the return values is very unclear. Please help
def on_message(ws, payload, is_binary):
# if ws.on_message:
# ws.on_message(ws, payload, is_binary)
#
# # If the message is binary, parse it and send it to the callback.
# if ws.on_ticks and is_binary and len(payload) > 4:
# ws.on_ticks(ws, ws._parse_binary(payload))
#
# # Parse text messages
if not is_binary:
print("Message arrived", ws._parse_text_message(payload))
You need to set callback on_order_update. You can check out more details here.
1. How can I know possible states for on_order_update (link for document)
2. How is on_order_update different from on_message
on_message
is not only meant for order updates. There are many other platform text messages. You need to listen to only order updates and ignore the rest.1. I modified order from Kite web browser but that event was not logged in my _on_order_update method
2. I created a websocket in a seperate thread, but Order Placing(CONFIRMED) was not logged. Why so?
3. I do not understand why multiple loggings are observed for cancellation event, only pending_quantity is changed.
4. I could capture logs for order fill and cancel but not for confirmation and modification
I have attached the logs for inspection. Few details of mine have been modified
1. We are already looking into this. It will be fixed shortly.
2. When you place an order and you get back an ID then it is confirmed. There is no confirmation update through WebSocket.
3. This is a long-standing issue from OMS. We have contacted them to fix this.
AlgoTrading using python notebook and excel using Zerodha's kite connect API
https://github.com/hemangjoshi37a/hjAlgos