Navigation

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

    unable to import websocket

    Python SDK
    5
    15
    127
    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.
    • L
      lavly last edited by

      WebSocket

      from smartapi import WebSocket
      FEED_TOKEN= "your feed token"
      CLIENT_CODE="your client Id"
      token="channel you want the information of" #"nse_cm|2885&nse_cm|1594&nse_cm|11536"

      ss = WebSocket(FEED_TOKEN, CLIENT_CODE)

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

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

      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( )

      This code giving error 1 line itself.

      D James Bond 2 Replies Last reply Reply Quote 0
      • D
        djdenish @lavly last edited by

        @lavly
        https://smartapi.angelbroking.com/topic/329/working-websocket-sample-code-to-retrieve-ltp-python

        1 Reply Last reply Reply Quote 0
        • James Bond
          James Bond @lavly last edited by James Bond

          @lavly
          Which pip version (pip or pip3) you used to install SmartAPI Python SDK and which Python version you're using ?
          Most probably this error occurs due to conflicting versions of pip and python while installing library.

          “Bond. James Bond.”

          L 2 Replies Last reply Reply Quote 0
          • L
            lavly @James Bond last edited by

            @James-Bond i am working with Google collaboratory. I'm getting my profile. Evry thing is ok.
            When I put cmd from smartapi import Web Socket it shows error no module found

            D 1 Reply Last reply Reply Quote 0
            • L
              lavly @James Bond last edited by

              @James-Bond it suppor pip pip3 is not working

              1 Reply Last reply Reply Quote 0
              • D
                djdenish @lavly last edited by djdenish

                @lavly
                Have you installed Smart API library??
                If not then go to cmd type : pip install smartapi-python
                Hit enter.

                L 1 Reply Last reply Reply Quote 0
                • L
                  lavly @djdenish last edited by

                  @djdenish installed. I'm getting my profile. But the codes given for WebSocket, order placement and gtt giving errors, like module not found or wrong indentation , define e. Etc

                  D S 2 Replies Last reply Reply Quote 0
                  • D
                    djdenish @lavly last edited by

                    @lavly
                    Post your code and error

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

                      @lavly said in unable to import websocket:

                      wrong indentation

                      This is a python error..

                      @lavly said in unable to import websocket:

                      But the codes given for WebSocket, order placement and gtt giving errors,

                      One step at a time. are you getting websockt data ?

                      L 1 Reply Last reply Reply Quote 0
                      • L
                        lavly @Surya 1 last edited by

                        @rajanprabu no

                        1 Reply Last reply Reply Quote 0
                        • L
                          lavly @djdenish last edited by

                          @djdenish from smartapi import WebSocket

                          Errorr


                          ModuleNotFoundError Traceback (most recent call last)
                          <ipython-input-47-fd07382cedc0> in <module>()
                          ----> 1 from smartapi import WebSocket

                          2 frames
                          /usr/local/lib/python3.7/dist-packages/twisted/internet/ssl.py in <module>()
                          56
                          57 # System imports
                          ---> 58 from OpenSSL import SSL
                          59
                          60 from zope.interface import implementer, implementer_only, implementedBy

                          ModuleNotFoundError: No module named 'OpenSSL'


                          NOTE: If your import is failing due to a missing package, you can
                          manually install dependencies using either !pip or !apt.

                          To view examples of installing some common dependencies, click the
                          "Open Examples" button below.

                          D 1 Reply Last reply Reply Quote 0
                          • D
                            djdenish @lavly last edited by

                            @lavly
                            open cmd type : pip install pyOpenSSL
                            hit enter.
                            after successful installation run your code again.

                            L N 2 Replies Last reply Reply Quote 0
                            • L
                              lavly @djdenish last edited by

                              @djdenish thanx

                              1 Reply Last reply Reply Quote 0
                              • N
                                neeluru @djdenish last edited by

                                @djdenish

                                I have faced the problem at ss.connect()
                                1def495f-da15-4c6c-9c87-dad1d89ac5c9-image.png

                                am running the code in colab

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

                                  @neeluru

                                  Please don't confuse on ws.send_request()

                                  2098168e-8776-47f4-ab07-693e5ee49fec-image.png

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