order updates during websocket disconnection

pawan12
hi if we use python client and use auto reconnect feature than is there a possibility of order updates getting missed during the reconnection process or once the reconnection is established we can expect those order updates.
  • rakeshr
    is there a possibility of order updates getting missed during the reconnection process
    Yes, it is possible, if WebSocket is down during the order_update message, then it will be missed.
    once the reconnection is established we can expect those order updates
    No, as it's a stream, you won't be able to fetch any previous messages.
    For such cases, you might have to fetch a complete order book and know the status of the required order.
  • pawan12
    so rather than always fetching orderbook set a flag during disconnect and once reconnected make sure all orders are there and than again rely on websocket.
  • pawan12
    @rakeshr can you post a thread/snippt of python websocket code where auto reconnect is used ?
  • pawan12
    import logging
    from kiteconnect import KiteTicker

    logging.basicConfig(level=logging.DEBUG)

    # Initialise
    kws = KiteTicker("your_api_key", "your_access_token")

    def on_ticks(ws, ticks):
    # Callback to receive ticks.
    logging.debug("Ticks: {}".format(ticks))

    def on_connect(ws, response):
    # Callback on successful connect.
    # Subscribe to a list of instrument_tokens (RELIANCE and ACC here).
    ws.subscribe([738561, 5633])

    # Set RELIANCE to tick in `full` mode.
    ws.set_mode(ws.MODE_FULL, [738561])



    # Assign the callbacks.
    kws.on_ticks = on_ticks
    kws.on_connect = on_connect


    # Infinite loop on the main thread. Nothing after this will run.
    # You have to use the pre-defined callbacks to manage subscriptions.
    kws.connect()
  • pawan12
    @rakeshr in above code by default reconnection is enabled as per documentation does this mean if websocket gets reconnected on_connect() will be called again and hence we would be able to resubscribe tokens ?
Sign In or Register to comment.