Navigation

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

    How to fetch live data for indices using websockets

    Python SDK
    0
    2
    45
    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.
    • S
      sevrus last edited by

      Here is how i am trying to get index ticks. But i am not getting the ticks. I dont if it is just me but the doc link https://smartapi.angelbroking.com/docs/WebSocket is nt working for me. Can someone point me to the right doc? or spot what is wrong in my code?

      indices = ["nse_cm|26000", "nse_cm|999022", "nse_cm|999031"]
      mode = 3
      token_list = [{"exchangeType": 1, "tokens": indices}]

      ws = SmartWebSocketV2(AUTH_TOKEN, API_KEY, CLIENT_CODE, FEED_TOKEN)
      ws.subscribe(correlation_id, mode, token_list)

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

        @sevrus
        from smartWebSocketV2 import SmartWebSocketV2

        For Live NIFTY, BANKNIFTY LTP

           AUTH_TOKEN = 
           angelapikey = 
           feed_token = 
           client_code = 
           correlation_id = "live_data"
           action = 1
           mode = 1
           sws = SmartWebSocketV2(AUTH_TOKEN, angelapikey, client_code, feed_token)
        
           token_Nifty = "26000"
           token_Bank = "26009"
           token_Fin = "26037"
           token_Mid = "26074"
        
           token_list = [{"exchangeType": 1, "tokens": [token_Nifty,token_Bank,token_Fin,token_Mid]}]
        
           def on_data(wsapp, message):
             # print("Ticks: {}".format(message))
             token = message['token']
             last_price = message['last_traded_price']
             last_price = last_price/100
               
            def on_open(wsapp):
                print("\n------Options Live LTP subscribed------")
                sws.subscribe(correlation_id, mode, token_list)
        
        
            def on_error(wsapp, error):
                print(error)
        
        
            def on_close(wsapp):
                print("Close")
        
            sws.on_open = on_open
            sws.on_data = on_data
            sws.on_error = on_error
            sws.on_close = on_close
        
            threading.Thread(target = sws.connect).start()
        

        "" Do check the indent correctly ""

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