Websocket of Order Status is not working.


  • I want to use web socket of order status mentioned in: https://smartapi.angelbroking.com/docs/WebSocketOrderStatus. But the URL mentioned in it seems to be not responding at all. My script is erroring out saying Connection to remote host was lost.

    Can you please check what is the issue?

    Code I am using to connect:

    self.ROOT_URI = 'wss://smartapisocket.angelbroking.com/websocket'
    ROOT_URL = f"{self.ROOT_URI}?jwttoken={self.jwttoken}&clientcode={self.client_code}&apikey={self.apiKey}"
    print(ROOT_URL)
    self.ws = websocket.WebSocketApp(ROOT_URL,
          #  header=headers,
          on_message=self.__on_message,
          on_close=self.__on_close,
          on_open=self.__on_open,
          on_error=self.__on_error
          )
    self.ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})
    

  • @Moderator_2 said in Websocket of Order Status is not working.:

    action = 1
    mode = 3
    token_list = [{"exchangeType": "1", "tokens": ["438"]}, {"exchangeType": "1", "tokens": ["13528"]}, {"exchangeType": "1", "tokens": ["2303"]}]

    Can you explain what these variables are and what are their possible values?

    • action
    • mode
    • token_list

  • @aakash2610

    Apologies for delayed response.
    Please find the sample code for websocket below.

    *AUTH_TOKEN = "token"
    API_KEY = "key"
    CLIENT_CODE = "code"
    FEED_TOKEN = "feed_token"
    correlation_id = "abc123"
    action = 1
    mode = 3
    token_list = [{"exchangeType": "1", "tokens": ["438"]}, {"exchangeType": "1", "tokens": ["13528"]}, {"exchangeType": "1", "tokens": ["2303"]}]

    #retry_strategy=0 for simple retry mechanism
    sws = SmartWebSocketV2(AUTH_TOKEN, API_KEY, CLIENT_CODE, FEED_TOKEN)

    def on_data(wsapp, message):
    logger.info("Ticks: {}".format(message))
    # close_connection()

    def on_control_message(wsapp, message):
    logger.info(f"Control Message: {message}")

    def on_open(wsapp):
    logger.info("on open")
    some_error_condition = False
    if some_error_condition:
    error_message = "Simulated error"
    if hasattr(wsapp, 'on_error'):
    wsapp.on_error("Custom Error Type", error_message)
    else:
    sws.subscribe(correlation_id, mode, token_list)
    # sws.unsubscribe(correlation_id, mode, token_list1)

    def on_error(wsapp, error):
    logger.error(error)

    def on_close(wsapp):
    logger.info("Close")

    def close_connection():
    sws.close_connection()

    Assign the callbacks.

    sws.on_open = on_open
    sws.on_data = on_data
    sws.on_error = on_error
    sws.on_close = on_close
    sws.on_control_message = on_control_message

    sws.connect()*

    Thanks & Regards,
    SmartAPI team


  • @Moderator_2, can you please share a working sample code for Websocket Order Status using Python SDK or general python code?


  • Hi @aakash2610 ,

    Apologies for delayed response.
    The endpoint "websocket" has been deprecated from our end.
    Kindly refer to the below documentation for the updated endpoints.
    https://smartapi.angelbroking.com/docs/WebSocket2

    Thanks & Regards,
    SmartAPI team


  • @admin, any update on this?