Navigation

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

    Connection problem with websocket2.0

    Python SDK
    0
    10
    100
    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.
    • M
      Manish Choudhary last edited by

      from SmartApi.smartConnect import SmartConnect
      from SmartApi.smartWebSocketV2 import SmartWebSocketV2
      from pyotp import TOTP
      import login as l 
      
      obj=SmartConnect(api_key=l.api_key)
      data=obj.generateSession(clientCode=l.user_name,password=l.password,totp=TOTP(l.token).now())
      Feed_token=obj.getfeedToken()
      Auth_token=data['data']['jwtToken']
      prof=obj.getProfile(data['data']['refreshToken'])
      
      sws=SmartWebSocketV2(auth_token=Auth_token,api_key=l.api_key,client_code=l.user_name,feed_token=Feed_token)
      
      def on_open(wsapp):
          print("open")
          sws.subscribe(correlation_id="stream_1",mode=3,token_list=[{"exchangeType": 1, "tokens": "1594"}])
      
      def on_data(wsapp,message):
          print("Tick : {}".format(message))
      
      def on_error(wsapp,error):
          print(error)  
      
      sws.on_open=on_open
      sws.on_data=on_data
      sws.on_error=on_error
      
      sws.connect()
      

      ------------------------------output---------------------------------

      On open
      [E 240129 15:00:23 smartWebSocketV2:218] Error occurred during subscribe: 'str' object has no attribute 'extend'
      [W 240129 15:00:23 smartWebSocketV2:326] Attempting to resubscribe/reconnect (Attempt 1)...
      On open
      [E 240129 15:00:44 smartWebSocketV2:218] Error occurred during subscribe: 'str' object has no attribute 'extend'
      
      Connection closed
      [W 240129 15:00:45 smartWebSocketV2:350] Connection closed due to max retry attempts reached.
      
      Connection closed
      [W 240129 15:00:45 smartWebSocketV2:350] Connection closed due to max retry attempts reached.
      
      Connection closed
      [W 240129 15:00:45 smartWebSocketV2:350] Connection closed due to max retry attempts reached.
      
      Connection closed
      [W 240129 15:00:45 smartWebSocketV2:350] Connection closed due to max retry attempts reached.
      
      Connection closed
      [W 240129 15:00:45 smartWebSocketV2:350] Connection closed due to max retry attempts reached.
      
      M 1 Reply Last reply Reply Quote 0
      • M
        Moderator_2 @Manish Choudhary last edited by

        Hi @Manish-Choudhary

        Apologies for delayed response.
        Please reverify on the no of connection, we have limit of three connection Websocket smartAPI, if total connection per client count reached 3 all new connection will be blocked.

        Thanks & Regards,
        SmartAPI team

        N V 2 Replies Last reply Reply Quote 0
        • N
          namit @Moderator_2 last edited by

          @Moderator_2 Hi this issue is not about having more than three connections. This issue comes even with only one connection with only one token subscribed. And this happens lot of time.
          Not only that, even if you unsubscribe the token using sws.unsubscribe(correlation_id, mode, token_list) and sws.close_connection(), it doesn't close and gets resubscribed.

          1 Reply Last reply Reply Quote 0
          • J
            jaideep siddula last edited by

            I'm getting "Attempting to resubscribe/reconnect for the past few days " . Any help is aprreciated.

            Thanks in advance.

            M 1 Reply Last reply Reply Quote 0
            • M
              Moderator_2 @jaideep siddula last edited by

              Hi @jaideep-siddula

              Kindly share which SDK version is consumed and error snapshot if possible to analyze issue from our end.

              Regards,
              SmartAPI team

              S J 3 Replies Last reply Reply Quote 0
              • S
                subh @Moderator_2 last edited by

                @Moderator_2
                I am getting same error,

                1 Reply Last reply Reply Quote 0
                • S
                  subh @Moderator_2 last edited by

                  @Moderator_2 Screenshot_20240301-073548_Chrome.jpg Screenshot_20240228-184452_Pydroid 3.jpg

                  1 Reply Last reply Reply Quote 0
                  • S
                    subh last edited by

                    @Moderator_2 I am getting same error kindly provide any solution for that. Same error in laptop
                    It easy to subscribe 2, 3 5 ... token but how to append 200 token ??

                    Here is screenshot of error,

                    ![1_1709309555278_Screenshot_20240301-123231_Pydroid 3.jpg](Uploading 100%) ![0_1709309555209_Screenshot_20240301-143218_Pydroid 3.jpg](Uploading 100%)

                    1 Reply Last reply Reply Quote 0
                    • J
                      jaideep siddula @Moderator_2 last edited by

                      @Moderator_2 I placed the websocket python file locally and importing it. Now it's working fine. Thank you. Didn't really know why it worked? Any comments?

                      1 Reply Last reply Reply Quote 0
                      • V
                        vishwendramore @Moderator_2 last edited by

                        @Moderator_2 add on more function like below

                        def _on_close(wsapp,code,reason):
                              on_close(wsapp)
                        

                        and add this function to sws object like below

                        sws._on_close=_on_close
                        

                        Above lines of code will resolve the issue of error during close.

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