Navigation

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

    Comparing static price with websocket LTP

    Python SDK
    2
    5
    54
    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.
    • G
      GaryR last edited by

      I have excel file with predefined buy/sell price. I want to execute order when ltp will be in the range.

      I have successfully connected websocket and fetching live data of all stocks.

      "How can I fetch specific stock's LTP from websocket?" Which further I have to compare with excel file and execute orders.

      I have tried these calls to get only ltp of specific tokens but did not get success.
      print("Ticks: {}".format(message.ltp))
      print("Ticks: {}".format(message).ltp)
      print("Ticks: {}".format(message [2])
      print("Ticks: {}".format(message){2})

      Please guide.

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

        HI @GaryR This is a user specific requirement please get in touch with your dev team.

        G 2 Replies Last reply Reply Quote 0
        • G
          GaryR @admin last edited by

          @admin Sir/Madam, I just need format of function which is not available on website. If it is available, then pls share link.

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

            HI @GaryR Please go through below link
            https://smartapi.angelbroking.com/docs/WebSocketStreaming

            1 Reply Last reply Reply Quote 0
            • G
              GaryR @admin last edited by

              sharing this if someone needs it.

              "Code to store live websocket data in dynamic dictionary"
              ....................................................................................................................

              from smartapi import SmartConnect
              from smartapi import SmartWebSocket

              subscribetoken = "nse_cm|2031&nse_cm|212&nse_cm|3045"
              live_data = {}

              def websocketstreaming ():
              FEED_TOKEN = feedToken
              CLIENT_CODE = credentials.USER_NAME

                  token = subscribetoken
                  task = "mw"
              
                  ss = SmartWebSocket(FEED_TOKEN, CLIENT_CODE)
              
                  def on_message(ws, message):
                      for i in message:
                          for j, k in i.items():
                                  if j == 'ltp':
                                      t = i.get('tk')  #token
                                      l = i.get('ltp')  #ltp
                                      #print(t, k)         
                                      live_data[t] = k  #storing token:ltp in dictionary 
                                      print(live_data)
                                  else:
                                      pass
              
                  def on_open(ws):
                      print("on open")
                      ss.subscribe(task, token)
              
                  def on_error(ws, error):
                      print(error)
              
                  def on_close(ws):
                      print("Close")
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post