Navigation

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

    Unable to fetch data using Python SDK

    Python SDK
    pythonsdk
    4
    9
    158
    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
      Lalitbaghel786 last edited by

      I am trying to fetch market data using the Python SDK. The reference documentation I am following is from here:
      https://github.com/angelbroking-github/smartapi-python

      The code is copy pasted from here without the order bit. On running the code, the on_close event gets triggered with the following code and reason:
      Code = 1006
      Reason = "connection was closed uncleanly (I dropped the WebSocket TCP connection: global name 'JSON' is not defined)"

      Is it a missing library that I need to install or some code issue? Can someone advise pls?

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

        Can someone help with this please?

        J 1 Reply Last reply Reply Quote 0
        • J
          jiwan1986 @Lalitbaghel786 last edited by

          @kpsidd Do you have the latest python SDK? I'm using the following code for the socket streaming.

          import time, json
          from smartapi import SmartConnect, WebSocket
          
          obj = SmartConnect(api_key="KEY")
          data = obj.generateSession("USER_ID","PASS")
          
          CLIENT_ID = 'ID'
          FEED_TOKEN = obj.getfeedToken()
          token = 'nse_cm|2885'
          
          ss = WebSocket(FEED_TOKEN, CLIENT_ID)
          
          def on_tick(ws, ticks):
          	print(ticks)
          
          def on_connect(ws, response):
          	print("on connect")
          	ws.send_request(token)
          
          def on_close(ws, code, reason):
          	print("on close")
          	ws.stop()
          
          
          ss.on_ticks = on_tick
          ss.on_connect = on_connect
          ss.on_close = on_close
          
          ss.connect()
          
          
          L 1 Reply Last reply Reply Quote 0
          • L
            Lalitbaghel786 @jiwan1986 last edited by

            @rjbanna Sorry, missed your reply.

            I have the latest SDK. I will try out with your code and see it.

            Will update.

            M 1 Reply Last reply Reply Quote 0
            • M
              mrchharus @Lalitbaghel786 last edited by

              @kpsidd !Hey I'm facing the same problem from last 2 days , but it was working fine before that Annotation 2021-01-19 113116.jpg This is my code and ouput

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

                @mrchharus you're passing wrong feedToken. Please review.

                M 2 Replies Last reply Reply Quote 0
                • M
                  mrchharus @admin last edited by

                  @admin I've been using this feed token from the starting

                  1 Reply Last reply Reply Quote 0
                  • M
                    mrchharus @admin last edited by

                    @admin Would you mind helping me sir as I've cross checked the feed token again and tried your another code to fetch data but it still the same

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

                      Hi @mrchharus , please share your contact details on api@angelbroking.com

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