Navigation

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

    Unable to get live feed.

    Python SDK
    0
    16
    208
    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.
    • B
      balaSP last edited by

      @admin I am able to get historical as well as ltp data. but when trying for live feed getting following output.
      __on_open################
      {'task': 'cn', 'channel': 'NONLM', 'token': '0968926247', 'user': 'B96820', 'acctid': 'B96820'}
      2022-05-29 13:27:52.873895 : Start task in the background
      {'task': 'hb', 'channel': '', 'token': '0968926247', 'user': 'B96820', 'acctid': 'B96820'}
      on open
      Ticks: [{'ak': 'ok', 'msg': 'connected', 'task': 'cn'}]
      Ticks: [{'ak': 'ok', 'msg': 'heartbeat', 'task': 'hb'}]
      Ticks: [{'ak': 'ok', 'msg': 'mw', 'task': 'mw'}]
      Ticks: [{'ak': 'ok', 'msg': 'mw', 'task': 'mw'}]
      Ticks: [{'ak': 'ok', 'msg': 'mw', 'task': 'mw'}]
      Ticks: [{'ak': 'ok', 'msg': 'mw', 'task': 'mw'}]
      2022-05-29 13:28:22.890306 : Start task in the background
      {'task': 'hb', 'channel': '', 'token': '0968926247', 'user': 'B96820', 'acctid': 'B96820'}
      Ticks: [{'ak': 'ok', 'msg': 'heartbeat', 'task': 'hb'}]
      @admin Will you please look where is the problem?
      Thank you.
      Following is the Code that I am using for live feed.

      from smartapi import SmartConnect
      from smartapi import SmartWebSocket

      apikey = 'MlxYOLdb'
      username = 'B96820'
      pwd = 'password'
      obj = SmartConnect(api_key=apikey)
      data = obj.generateSession(username,pwd)
      refreshToken= data['data']['refreshToken']
      feedToken=obj.getfeedToken()
      FEED_TOKEN = feedToken#"0980248722"
      CLIENT_CODE = username
      token = "nse_fo|108809&nse_fo|56855&nse_fo|5694&nse_fo|56906"
      ss = SmartWebSocket(FEED_TOKEN, CLIENT_CODE)
      task = "mw"

      def on_message(ws, message):
      print("Ticks: {}".format(message))

      def on_open(ws):
      ss.subscribe(task, token)
      print("on open")
      ss.subscribe(task, token)

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

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

      ss._on_open = on_open
      ss._on_message = on_message
      ss._on_error = on_error
      ss._on_close = on_close

      ss.connect()

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

        @balaSP I facing same issue. Please let me know if you have any other solution for python.
        @admin Any update here?

        B 1 Reply Last reply Reply Quote 0
        • B
          balaSP @nehak last edited by

          @nehak During market hours, live data is coming.

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

            @balaSP @nehak Please use Websocket 2.0 - https://smartapi.angelbroking.com/topic/1861/user-feedback-websocket-2-0-beta-rollout-python-language?_=1653996853593

            B S 2 Replies Last reply Reply Quote 0
            • B
              balaSP @admin last edited by

              @admin Please explain about two fields AUTH_TOKEN and correlation_id. How to get values for these two fields?

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

                Code isn't finished?

                1 Reply Last reply Reply Quote 0
                • S
                  Sukhwant280 @admin last edited by Sukhwant280

                  @admin I am not clear what needs to be entered in AUTH_TOKEN and correlation_id. Couldnt find anything on the documentation as well.

                  Please help

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

                    @admin - found answers to my question on documentation here https://drive.google.com/drive/u/0/folders/1GMwTMfxRdiloUziV4DYwlYchGXbOvTfL

                    follow up question : for AUTH_TOKEN, its mentioned (jwt auth token received from Login API). How do we generate auth token login api?

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

                      @admin - is AUTH_TOKEN same as Secret-Key ?

                      Mnagesh 1 Reply Last reply Reply Quote 0
                      • Mnagesh
                        Mnagesh @Sukhwant280 last edited by

                        @Sukhwant280 can you elaborate your Q? with part of code or function and its error or output

                        Now I am full time Algo Trader and successfully developed my own Apps for my personal use.

                        S 1 Reply Last reply Reply Quote 0
                        • S
                          Sukhwant280 @Mnagesh last edited by

                          @Mnagesh - Below is the code form websocket vs 2

                          my question is from where do we get AUTH_TOKEN. I tried adding "Secret-Key" from "Apps & API" section (i.e. this link -> https://smartapi.angelbroking.com/apps) but I get below feeds from websocket.

                          Code
                          from SmartApi.smartWebSocketV2 import SmartWebSocketV2

                          AUTH_TOKEN = 'Bearer eyJhbGciOiJIUzU-w'
                          API_KEY = 'qwert'
                          CLIENT_CODE = 'X123456'
                          FEED_TOKEN = '00998877'

                          correlation_id = "nishant_123_qwerty"
                          action = 1
                          mode = 3

                          Websocket feed:
                          In on pong function==> b'\x00'

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

                            Hi @Sukhwant280 , Auth_token is JWT token obtained at the time of generating the session using loginbypassword api call.

                            S 1 Reply Last reply Reply Quote 0
                            • S
                              Sukhwant280 @admin last edited by

                              @admin - Thanks. Now I am using below in my code
                              AUTH_TOKEN -> jwtToken from response from generateSession('userid', 'password')
                              FEED_TOKEN -> refreshToken from response from generateSession('userid', 'password')

                              Please confirm if above is not correct, coz still I am getting same response from websockt i.e "Attempting to resubscribe/reconnect...
                              In on pong function==> b'\x00'"

                              I tried to troubleshoot from my end -> it failing at below step (i.e. row no 310 in smartWebsocketV2.py:

                              "token": SmartWebSocketV2._parse_token_value(binary_data[2:27]),

                              Can you help me here to understand whats wrong in my inputs ?

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

                                Hi @Sukhwant280

                                FeedToken is different from refreshToken

                                jwtToken, refreshToken and feedToken are generated after successful login into your account via SmartAPI.

                                feedToken is required to be passed to a WebSocket connection request to start successful streaming of tick data.

                                Please read more about this in our documentation.

                                S 1 Reply Last reply Reply Quote 0
                                • S
                                  Sukhwant280 @admin last edited by

                                  @admin
                                  I get below response from generateSession. I cant find any relevant for FEED_TOKEN.

                                  {"status": True,
                                  "message": "SUCCESS",
                                  "errorcode": "",
                                  "data": {
                                  "clientcode": "XXXXXX",
                                  "name": "XXXX YYYY",
                                  "email": "",
                                  "mobileno": "",
                                  "exchanges": ["bse_cm", "nse_cm", "nse_fo"],
                                  "products": ["BO", "NRML", "CO", "CNC", "MIS", "MARGIN"],
                                  "lastlogintime": "",
                                  "broker": "",
                                  "jwtToken": "Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
                                  "refreshToken": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
                                  }
                                  }

                                  Also, are you referring to below doc ? I cant find anything which explains which field to take from api response. Pleas advise
                                  https://docs.google.com/document/d/1tZQzU2qNrB98eso6e6yqF3YxvXfK9cn5Xkzw_5jSJL8/edit

                                  J 1 Reply Last reply Reply Quote 0
                                  • J
                                    J88913 @Sukhwant280 last edited by

                                    @Sukhwant280 use this code for feedtoken
                                    feedToken = obj.getfeedToken()

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