WebSocket delay issues update

Vivek
We have released a experimental version of pykiteconnect with major changes to WebSocket api - https://github.com/rainmattertech/pykiteconnect/tree/autobahn

Users experiencing market live ticks delay issue can try this and share results with us.
  • cisk
    cisk edited January 2018
    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!

    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
  • sujith
    The new Kite ticker authentication is based on access token. Are you using new URL with access token?
  • rayi
    @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
    sujith edited January 2018
    It is a new TODO as a part of Kite Connect 3.
  • rayi
    what extra I have to do? i am already using the apikey,public token and access token ? when will it go live?
  • cisk
    cisk edited January 2018
    @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
  • sujith
    @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.
  • cisk
    cisk edited January 2018
    @sujith I am using http://techmonies.com URL as redirect URL for my app and am using the API example in https://github.com/zerodhatech/pykiteconnect/tree/kite3 to generate the access token. Then I used this same access token to create my KiteTicker object:

    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
    @cisk Add one more parameter to your ticker constructor as root="wss://websocket.kite.trade/v3". This will connect ticker to our new backend.
  • cisk
    @tonystark Thanks that helped. But now i've run into another problem. I'm getting following trace, wondering whats causing the connection to get lost

    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
    ].
  • tonystark
    @cisk When this happened? Immediately when you started or after getting some ticks? Can you give a code snippet that can reproduce this issue?
  • cisk
    @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
    @cisk,
    You need to set callback on_order_update. You can check out more details here.
  • cisk
    @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
  • sujith
    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.
  • cisk
    cisk edited January 2018
    @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
  • tonystark
    @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.
  • cisk
    Thank you @tonystark for the detailed explanation.
  • hemangjoshi37a
    ???? hjAlgos ????
    AlgoTrading using python notebook and excel using Zerodha's kite connect API
    https://github.com/hemangjoshi37a/hjAlgos
Sign In or Register to comment.