Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    Unable to unsubscribe the symbol in WebSocket and close the connection

    Python SDK
    0
    6
    69
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • N
      namit last edited by namit

      Hi I am unable to unsubscribe the symbol when i don't need it. Even after unsubscribing it using sws.unsubscribe(correlation_id, mode, token_list) and trying to close the connection using sws.close_connection(), it doesn't close the connection but the symbol gets re-subscribe.
      What is the issue?

      for more details sharing the code.

      global correlation_id, mode, sws

          AUTH_TOKEN = credential.range('b8').value
          angelapikey = credential.range('b4').value
          feed_token = credential.range('b7').value
          client_code = credential.range('b2').value
          correlation_id = "option_live_data"
          action = 1
          mode = 1
          sws = SmartWebSocketV2(AUTH_TOKEN, angelapikey, client_code, feed_token)
      
          token_list = [{"exchangeType": 1, "tokens": [token_Nifty,token_Bank,token_Fin,token_Mid]}]
          
          token_Nifty = "26000"
          token_Bank = "26009"
          token_Fin = "26037"
          token_Mid = "26074" 
          def on_data(wsapp, message):
              # print("Ticks: {}".format(message))
              
              token = message['token']
              last_price = message['last_traded_price']
              last_price = last_price/100
              print(last_price)
      
      
          def on_open(wsapp):
              print("\n------Options Live LTP subscribed------")
              sws.subscribe(correlation_id, mode, token_list)
      
      
          def on_error(wsapp, error):
              print(error)
      
      
          def on_close(wsapp):
              print("Close")
      
          sws.on_open = on_open
          sws.on_data = on_data
          sws.on_error = on_error
          sws.on_close = on_close
      
          threading.Thread(target = sws.connect).start()
      
      def ws_disconnect():
          print("\n------ Unsubscribed Options ------")
          sws.unsubscribe(correlation_id, mode, token_list)
          sws.close_connection()
      
      M M 2 Replies Last reply Reply Quote 0
      • M
        Moderator_2 @namit last edited by

        Hi @namit

        We are analyzing on the query. Will update for the same.

        Thanks & Regards,
        SmartAPI team

        N 1 Reply Last reply Reply Quote 0
        • N
          namit @Moderator_2 last edited by

          @Moderator_2 Have you analysed it yet?

          D 1 Reply Last reply Reply Quote 0
          • D
            Deepak9097 @namit last edited by

            @admin Have you find any solution ?
            I want to make Websocket connection with interval of 10-15 sec.
            How's this possible?

            C 1 Reply Last reply Reply Quote 0
            • C
              chetansuri @Deepak9097 last edited by

              @Deepak9097 websocket connection is for continuous data and you can use it as it is. you don't want to run it every 15 seconds just to get 1 tick of data. You can have your analysis setup based on 15 seconds interval or so.

              1 Reply Last reply Reply Quote 0
              • M
                Moderator_3 @namit last edited by

                Hello @namit
                @chetansuri is already replied to your concern
                Regards,
                SmartAPI Team

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post