Navigation

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

    Unable to get to tick data

    Python SDK
    0
    6
    81
    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.
    • R
      Ramesh last edited by

      @admin , I used to get the tick data by using the below code, in the recent past it was NOT providing the tick data, can you pl help me know if anything needs to be updated?

      from smartapi import SmartConnect # or from smartapi.smartConnect import SmartConnect
      #from smartapiwebsocket import SmartWebSocket
      from smartapi import SmartWebSocket

      ANGEL_API_KEY = "XXXXXX"
      #ANGEL_SEC_KEY = "XXXXX"
      TOTP="XXXXX"

      ANGEL_CLIENT_ID = "XXXXXX"
      ANGEL_PASSSWORD = "XXXXX"

      refreshToken = None
      feedToken = None
      smartObj = None

      tokens = None
      ss = None
      task = None

      def smartApiInitialization():
      global refreshToken
      global feedToken
      global smartObj

      try:
      

      smartObj = SmartConnect(api_key=ANGEL_API_KEY)
      totp = pyotp.TOTP(TOTP) #'replace with Text that appears below QR code'
      totp = totp.now()
      print("pasrse: ",totp)
      attempts = 5
      while attempts > 0:
      attempts = attempts - 1

      data = self.smartObj.generateSession(ANGEL_CLIENT_ID,ANGEL_PASSSWORD,totp)
      print(data)
      if data['status']:
      break
      time.sleep(2)

      refreshToken = data['data']['refreshToken']
      print(refreshToken)

      fetch the feedtoken

      feedToken = self.smartObj.getfeedToken()
      print(feedToken)
      time.sleep(1)

      except Exception as ex:

      print("Exception in smartApiInitialization method : {}".format(str(ex)))

      def on_message(ws, message):

      print("Ticks: {}".format(message))
      

      def on_open(ws):
      global tokens
      global task
      global ss

      print("on open")
      ss.subscribe(task, tokens)
      

      def on_error(ws, error):
      print(error)

      def on_close(ws):
      print("Close")

      def initialize_websocket():
      global tokens
      global ss
      global task
      global feedToken

      try:
      
          tokens = "nse_cm|26000&nse_cm|26009"
          task = "mw"
          ss = SmartWebSocket(feedToken, ANGEL_CLIENT_ID)
      
          # Assign the callbacks.
          ss._on_open = on_open
          ss._on_message = on_message
          ss._on_error = on_error
          ss._on_close = on_close
      
         ss.connect()
      
      except Exception as ex:
          print('exception in initialize_websocket : {}'.format(ex))
      

      if name == 'main':

      smartApiInitialization()
      initialize_websocket()
      
      M 1 Reply Last reply Reply Quote 2
      • M
        mohan1710 @Ramesh last edited by

        @Ramesh i am facing similar issue and no response for my post as well

        R 1 Reply Last reply Reply Quote 0
        • R
          Ramesh @mohan1710 last edited by

          @mohan1710 @admin pl help us

          R S 2 Replies Last reply Reply Quote 0
          • R
            Ramesh @Ramesh last edited by

            @admin pl reply

            R 1 Reply Last reply Reply Quote 0
            • R
              Ramesh @Ramesh last edited by

              @admin, do we have any active support or not?

              1 Reply Last reply Reply Quote 0
              • S
                skgkrish @Ramesh last edited by

                @Ramesh
                Same here.. tick data does not work with both websocket1 and websocket2

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