Navigation

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

    WebSocket functionality issue

    General Discussion
    4
    10
    112
    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.
    • K
      Kamal last edited by

      Hi All,
      I am using below code to get bid/ask volume.

      • from smartapi import SmartConnect
        #from smartapi import WebSocket
        from smartapi import SmartWebSocket

      obj=SmartConnect(api_key=api_key)
      data = obj.generateSession(clientId, password)
      FEED_TOKEN=obj.getfeedToken()

      ''' SBIN'''
      token="nse_cm|3045"
      task="dp" #'mw'|'sfi'|'dp'
      ws = SmartWebSocket(FEED_TOKEN, clientId)

      def on_tick(ws, tick):
      for i in tick:
      if 'tbq' in i.keys():
      print(i['tbq'])
      print(i['tsq'])
      ws.stop()

      def on_connect(ws, response):
      ws.send_request(token,task)

      def on_close(ws):
      ws.stop()

      ws.on_ticks = on_tick
      ws.on_connect = on_connect
      ws.on_close = on_close

      ws.connect()

      Challanges:

      1. While importing lib, from smartapi import WebSocket facing (C:\Users\kamal\anaconda3\lib\site-packages\smartapi_init_.py) error. Tried from smartapi import SmartWebSocket & it is working fine
      2. Ticker is not giving task 'dp', instead looping the task 'hb'.

      __on_open################
      {'task': 'cn', 'channel': 'NONLM', 'token': 'XXXXXX', 'user': 'XXXXXX', 'acctid': 'XXXXXX'}
      2021-06-21 17:18:04.942797 : Start task in the background
      {'task': 'hb', 'channel': '', 'token': 'XXXXXX', 'user': 'XXXXXX', 'acctid': 'XXXXXX'}
      2021-06-21 17:18:34.953644 : Start task in the background
      {'task': 'hb', 'channel': '', 'token': 'XXXXXX', 'user': 'XXXXXX', 'acctid': 'XXXXXX'}
      2021-06-21 17:19:04.957672 : Start task in the background
      {'task': 'hb', 'channel': '', 'token': 'XXXXXX', 'user': 'XXXXXX', 'acctid': 'XXXXXX'}
      {'task': 'hb', 'channel': '', 'token': '0999895434', 'user': 'V183756', 'acctid': 'V183756'}
      HeartBeat Sending Failed --> this is in loop after stopping manually.

      1. I had to stop manually, tried but service running in background not able to stop.

      I just need market depth, can someone help me/correct my code?

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

        @Kamal

        Which SDK version are you using ??

        K 1 Reply Last reply Reply Quote 0
        • K
          Kamal @Surya 1 last edited by

          @rajanprabu Thanks for your response

          smartapi-python==1.2.9
          websocket-client==1.1.0

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

            @Kamal

            I faced the same issue today. Its frustrating that HB issues still not resolved.

            K 1 Reply Last reply Reply Quote 0
            • K
              Kamal @Surya 1 last edited by

              @admin

              Could you help or can you share working code including packages along with versions

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

                Hi @Kamal Please go thorugh the below doc
                https://github.com/angelbroking-github/smartapi-python

                K 1 Reply Last reply Reply Quote 0
                • K
                  Kamal @admin last edited by

                  @admin

                  Thanks for the response,

                  I used same code for getting market depth. Total buy/sell volume. As per Official documentation says, "tbq/tsq" gives the numbers. But not present in API response.

                  32 tbq Total buy quantity
                  33 tsq Total sell quantity

                  task="dp"

                  Sample Output:
                  Ticks: [{'bno': '5', 'bno1': '14', 'bno2': '29', 'bno3': '26', 'bno4': '40', 'bp': '430.40', 'bp1': '430.35', 'bp2': '430.30', 'bp3': '430.25', 'bp4': '430.20', 'bq': '2778', 'bq1': '6556', 'bq2': '15776', 'bq3': '8624', 'bq4': '17065', 'bs': '450', 'bs1': '2518', 'bs2': '13472', 'bs3': '5992', 'bs4': '8936', 'e': 'nse_cm', 'name': 'dp', 'sno': '1', 'sno1': '16', 'sno2': '34', 'sno3': '23', 'sno4': '43', 'sp': '430.50', 'sp1': '430.55', 'sp2': '430.60', 'sp3': '430.65', 'sp4': '430.70', 'tk': '3045'}]

                  I am trying to get "bid/ask" volume along with LTP, any alternate?

                  Thanks in advance,
                  Kamal.

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

                    HI @Kamal Currenlty we are working on websocket once fixed we will update you.

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

                      @admin is your websocket got updated ?

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

                        HI @sapravi6 said in WebSocket functionality issue:

                        @admin is your websocket got updated ?

                        We dont have any update on this our team is working on this.

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