Navigation

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

    Facing problem when streaming the live data

    General Discussion
    4
    27
    186
    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.
    • A
      admin last edited by

      Hi @nayan_nandi please try below piece of code.

      from smartapi import WebSocket
      FEED_TOKEN= ""
      CLIENT_CODE=""
      token= "nse_cm|2885&nse_cm|1594&nse_cm|11536"
      task="mw" #'mw'|'sfi'|'dp'
      ss = WebSocket(FEED_TOKEN, CLIENT_CODE)

      def on_tick(ws, tick):
      print("Ticks: {}".format(tick))

      def on_connect(ws, response):
      ws.send_request(token,task)

      def on_close(ws, code, reason):
      ws.stop()

      Assign the callbacks.

      ss.on_ticks = on_tick
      ss.on_connect = on_connect
      ss.on_close = on_close

      ss.connect( )

      N 1 Reply Last reply Reply Quote 0
      • N
        nayan_nandi @admin last edited by nayan_nandi

        @admin Sir when i run the code it's showing like this___
        ghgfh.PNG
        and sir can you please tell me how to get the scripts token list including equity, futures, options.......

        A 1 Reply Last reply Reply Quote 0
        • A
          admin @nayan_nandi last edited by

          Hi @nayan_nandi Web socket only works in live markets so try it in market hours.

          N 1 Reply Last reply Reply Quote 0
          • N
            nayan_nandi @admin last edited by nayan_nandi

            @admin Sir same problem in market hours
            Captugfhre.PNG
            I'm using Trading API. And when I print feedToken it's print "None" my code is____

            from smartapi import SmartConnect
            from smartapi import WebSocket
            
            obj = SmartConnect(api_key=apikey)
            data = obj.generateSession(client_token, password)
            feedToken = obj.getfeedToken()
            
            print(feedToken)
            
            FEED_TOKEN = feedToken
            CLIENT_CODE = client_token
            
            token = "nse_cm|2885"  # Token number of RELIANCE-EQ
            task = "mw"  # 'mw'|'sfi'|'dp'
            ss = WebSocket(FEED_TOKEN, CLIENT_CODE)
            
            
            def on_tick(ws, tick):
                print("Ticks: {}".format(tick))
            
            
            def on_connect(ws, response):
                ws.send_request(token, task)
            
            
            def on_close(ws, code, reason):
                ws.stop()
            
            
            ss.on_ticks = on_tick
            ss.on_connect = on_connect
            ss.on_close = on_close
            
            ss.connect()
            
            A 1 Reply Last reply Reply Quote 0
            • A
              admin @nayan_nandi last edited by

              Hi @nayan_nandi we are testing it from our side.we will update you on this.

              N 1 Reply Last reply Reply Quote 0
              • N
                nayan_nandi @admin last edited by nayan_nandi

                @admin Sir any update ????
                Same problem today also
                Captfghure.PNG

                A 1 Reply Last reply Reply Quote 0
                • S
                  Surya 1 @Surya 1 last edited by

                  @rajanprabu said in Facing problem when streaming the live data:

                  @nayan_nandi
                  if you using new 1.2.2 python SDK you need to send task parameter as well.
                  def on_connect(ws, response):
                  ws.send_request(token,'mw')

                  did you try this @nayan_nandi ?

                  1 Reply Last reply Reply Quote 0
                  • A
                    admin @nayan_nandi last edited by

                    Hi @nayan_nandi we regret for the delay we will keep you updated on the issue.

                    N 1 Reply Last reply Reply Quote 0
                    • N
                      nayan_nandi @admin last edited by

                      @admin Sir can you please tell me what is the issue is happening???
                      And why it's happening.......

                      A 1 Reply Last reply Reply Quote 0
                      • A
                        admin @nayan_nandi last edited by

                        Hi @nayan_nandi we have tried to handle all this issues in the new version of python sdk.We will be testing it and reverting you back.

                        1 Reply Last reply Reply Quote 0
                        • A
                          admin last edited by

                          Hi @nayan_nandi we have tested the web socket today it is working fine now.

                          N 1 Reply Last reply Reply Quote 0
                          • N
                            nayan_nandi @admin last edited by nayan_nandi

                            @admin Sir the issues is not not resolve yet. Same problem facing today also....
                            dsfasewrewr.PNG
                            Please do something....

                            A 1 Reply Last reply Reply Quote 0
                            • A
                              admin @nayan_nandi last edited by

                              Hi @nayan_nandi web socket is working fine from our end.WEB SOCKET@@.PNG

                              N 1 Reply Last reply Reply Quote 0
                              • N
                                nayan_nandi @admin last edited by nayan_nandi

                                @admin So sir why i'm not getting feed. also when i trying to print feedToken it's show None what can i do.....
                                This is my code______

                                from smartapi import SmartConnect
                                from smartapi import WebSocket
                                import creds
                                
                                obj = SmartConnect(api_key=creds.api_key)
                                data = obj.generateSession(creds.client_token, creds.password)
                                feedToken = obj.getfeedToken()
                                
                                print(feedToken)
                                
                                FEED_TOKEN = feedToken
                                CLIENT_CODE = creds.client_token
                                
                                token = "nse_cm|2885"  # Token number of RELIANCE-EQ
                                task = "mw"  # 'mw'|'sfi'|'dp'
                                ss = WebSocket(FEED_TOKEN, CLIENT_CODE)
                                
                                
                                def on_tick(ws, tick):
                                    print("Ticks: {}".format(tick))
                                
                                
                                def on_connect(ws, response):
                                    ws.send_request(token, task)
                                
                                
                                # def on_close(ws, code, reason):
                                #     ws.stop()
                                
                                
                                ss.on_ticks = on_tick
                                ss.on_connect = on_connect
                                # ss.on_close = on_close
                                
                                ss.connect()
                                
                                
                                A 2 Replies Last reply Reply Quote 0
                                • A
                                  admin @nayan_nandi last edited by

                                  Hi @nayan_nandi we will review the code and revert you back.

                                  1 Reply Last reply Reply Quote 0
                                  • A
                                    admin @nayan_nandi last edited by

                                    Hi @nayan_nandi try to restart you kernel and give a try.

                                    N 1 Reply Last reply Reply Quote 0
                                    • N
                                      nayan_nandi @admin last edited by

                                      @admin How can i do it sir??

                                      A 1 Reply Last reply Reply Quote 0
                                      • A
                                        admin @nayan_nandi last edited by

                                        Hi @nayan_nandi can you please restart your system and give a try.

                                        N 1 Reply Last reply Reply Quote 0
                                        • N
                                          nayan_nandi @admin last edited by nayan_nandi

                                          @admin Sir I did but sowing same thing____

                                          "C:\Python 3.9.2\python.exe" C:/Users/Nayan/PycharmProjects/Angel_Broking/main.py
                                          None
                                          <function on_connect at 0x00000026BF9B7F70>
                                          Ticks: [{'ak': 'nk', 'msg': 'mw', 'task': 'mw'}]
                                          
                                          Process finished with exit code -1
                                          

                                          I'm using trading api.....

                                          S 1 Reply Last reply Reply Quote 0
                                          • S
                                            Surya 1 @nayan_nandi last edited by

                                            @nayan_nandi

                                            You need to add ws.websocket_connection()

                                            try with the following code

                                            from smartapi import SmartConnect
                                            from smartapi import WebSocket
                                            import creds
                                            
                                            obj = SmartConnect(api_key=creds.api_key)
                                            data = obj.generateSession(creds.client_token, creds.password)
                                            feedToken = obj.getfeedToken()
                                            
                                            print(feedToken)
                                            
                                            FEED_TOKEN = feedToken
                                            CLIENT_CODE = creds.client_token
                                            
                                            token = "nse_cm|2885"  # Token number of RELIANCE-EQ
                                            task = "mw"  # 'mw'|'sfi'|'dp'
                                            ss = WebSocket(FEED_TOKEN, CLIENT_CODE)
                                            
                                            
                                            def on_tick(ws, tick):
                                                print("Ticks: {}".format(tick))
                                            
                                            
                                            def on_connect(ws, response):
                                                ws.send_request(token, task)
                                            
                                            
                                            # def on_close(ws, code, reason):
                                            #     ws.stop()
                                            
                                            
                                            ss.on_ticks = on_tick
                                            ss.on_connect = on_connect
                                            # ss.on_close = on_close
                                            
                                            ss.connect()
                                            
                                            N 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post