Navigation

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

    Python Streaming Tick Data Problem with SmartAPI Websocket's

    Python SDK
    4
    12
    182
    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.
    • A
      adi3399 @admin last edited by

      @admin Thank you

      A 1 Reply Last reply Reply Quote 0
      • A
        azkhan @adi3399 last edited by

        This post is deleted!
        A 1 Reply Last reply Reply Quote 0
        • A
          azkhan @azkhan last edited by

          This post is deleted!
          A 1 Reply Last reply Reply Quote 0
          • A
            adi3399 @azkhan last edited by

            @azkhan added on_open() function.. still it is not showing tick price info. this is new code

            7f98b4ae-2855-404c-a4df-6876335919d9-image.png

            A 1 Reply Last reply Reply Quote 0
            • A
              azkhan @adi3399 last edited by

              @adi3399 please update your SmartAPI Python library.

              A 1 Reply Last reply Reply Quote 0
              • A
                adi3399 @azkhan last edited by

                @azkhan Uninstalled and re-installed smartapi python package. There is progress now. it is opening websocket connection and showing response. I need stock price information.. how can I get price? Please advise.

                Below is the output of same code. It is showing actual client code correctly , but to show here I changed it to "my client code"

                before connect
                __on_open################
                {'task': 'cn', 'channel': 'NONLM', 'token': 'token number', 'user': 'my client id', 'acctid': 'my client id'}
                2021-07-15 13:51:05.092349 : Start task in the background
                {'task': 'hb', 'channel': '', 'token': 'token number', 'user': 'my client id', 'acctid': 'my client id'}
                2021-07-15 13:51:21.833013 : Start task in the background
                {'task': 'hb', 'channel': '', 'token': 'token number', 'user': 'my client id', 'acctid': 'my client id'}
                HeartBeat Sending Failed
                2021-07-15 13:51:29.792444 : Start task in the background
                {'task': 'hb', 'channel': '', 'token': 'token number', 'user': 'my client id', 'acctid': 'my client id'}
                HeartBeat Sending Failed
                2021-07-15 13:51:35.124963 : Start task in the background
                {'task': 'hb', 'channel': '', 'token': 'token number', 'user': 'my client id', 'acctid': 'my client id'}
                2021-07-15 13:51:51.841917 : Start task in the background
                {'task': 'hb', 'channel': '', 'token': 'token number', 'user': 'my client id', 'acctid': 'my client id'}
                HeartBeat Sending Failed
                2021-07-15 13:51:59.822315 : Start task in the background
                {'task': 'hb', 'channel': '', 'token': 'token number', 'user': 'my client id', 'acctid': 'my client id'}
                HeartBeat Sending Failed

                A 1 Reply Last reply Reply Quote 0
                • A
                  azkhan @adi3399 last edited by

                  @adi3399
                  Go to this link to find the token information of all tradable instruments : https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json

                  Then Use this code to get live data streaming for any stock or Index
                  Getting started with SmartAPI Websocket's :

                  from smartapi import SmartConnect
                  from smartapi import SmartWebSocket

                  Live_Data_API = " Enter Your API Key Here"

                  Username = "Enter Your Angel Broking User name"

                  Password = "Enter Your Angel Broking Password"

                  #create object of call
                  obj=SmartConnect(api_key=Live_Data_API)

                  #login api call

                  data = obj.generateSession(Username,Password)
                  refreshToken= data['data']['refreshToken']

                  #fetch the feedtoken
                  feedToken=obj.getfeedToken()

                  #fetch User Profile
                  userProfile= obj.getProfile(refreshToken)

                  feed_token=092017047

                  FEED_TOKEN=feedToken
                  CLIENT_CODE=Username

                  token="mcx_fo|224395"

                  token="EXCHANGE|TOKEN_SYMBOL" #SAMPLE: nse_cm|2885&nse_cm|1594&nse_cm|11536&nse_cm|3045

                  token="mcx_fo|226745&mcx_fo|220822&mcx_fo|227182&mcx_fo|221599"

                  task="mw" # mw|sfi|dp

                  ss = SmartWebSocket(FEED_TOKEN, CLIENT_CODE)

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

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

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

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

                  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()

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

                    @adi3399
                    For more Info on websocket go to this link : https://smartapi.angelbroking.com/docs/WebSocketStreaming

                    1 Reply Last reply Reply Quote 0
                    • W
                      webseos last edited by

                      I am new to python. Can you guide how to install all these in python.. I mean what software I shall install like "pycharm" or other. Then anything else I need to download

                      Then what to be done , a complete guide for a new person.

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

                        HI @webseos You can download anaconda and use spyder for development also for detail understanding you can attend today's webinar on integration of smartapi using python..fr basic codes you can go through below thread.
                        https://smartapi.angelbroking.com/topic/1194/basic-smartapi-integration-using-python

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