Navigation

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

    ❗❗❗ How to get tick data of BID PRICE, ASK PRICE ❗❗❗

    Python SDK
    pythonsdk
    4
    15
    211
    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.
    • S2108014
      S2108014 @chimntu last edited by S2108014

      This post is deleted!
      1 Reply Last reply Reply Quote 0
      • C
        chimntu @S2108014 last edited by

        @James-Bond
        Why your post gets deleted??❗❗❗

        1 Reply Last reply Reply Quote 0
        • S2108014
          S2108014 @chimntu last edited by

          @djdenish

          from smartapi import SmartConnect 
          from smartapi import WebSocket 
          
          obj=SmartConnect(api_key="api_key")
          data = obj.generateSession('clientId','password')
          feedToken=obj.getfeedToken()
          
          FEED_TOKEN= feedToken
          CLIENT_CODE= 'clinetId'
          
          # SBIN
          token="nse_cm|3045"
          WS = WebSocket(FEED_TOKEN, CLIENT_CODE)
          
          
          def on_tick(ws, tick):
              for i in tick:
                  if 'bp' in i.keys():
                      print(f"Buying Price: {i['bp']} \t Selling Price: {i['sp']}")
              
          def on_connect(ws, response):
              ws.send_request(token)
          
          def on_close(ws, code, reason):
              ws.stop()
          
          # Assign the callbacks.
          WS.on_ticks = on_tick
          WS.on_connect = on_connect
          WS.on_close = on_close
          WS.connect()
          
          C 1 Reply Last reply Reply Quote 0
          • C
            chimntu @S2108014 last edited by

            @James-Bond
            WS = WebSocket(FEED_TOKEN, CLIENT_CODE)
            TypeError: init() missing 1 required positional argument: 'task'

            S2108014 1 Reply Last reply Reply Quote 0
            • S2108014
              S2108014 @chimntu last edited by S2108014

              @djdenish
              Screenshot 2021-03-08 at 2.44.03 PM.png

              I'm able to get Bid and Ask price successfully with same code. Can you check your credentials one more time ?

              I once faced same issue which is primarily because of wrong credentials I'm using.

              C S2108014 3 Replies Last reply Reply Quote 0
              • C
                chimntu @S2108014 last edited by

                @James-Bond
                Ok let me check.

                1 Reply Last reply Reply Quote 0
                • S2108014
                  S2108014 @S2108014 last edited by S2108014

                  @djdenish

                  I'm using old version of SmartAPI so it doesn't requires task param.
                  You just need to change following

                  # SBIN
                  token="nse_cm|3045"
                  WS = WebSocket(FEED_TOKEN, CLIENT_CODE)
                  

                  with this

                  token="nse_cm|3045"
                  task="mw" #'mw'|'sfi'|'dp'
                  WS = WebSocket(FEED_TOKEN, CLIENT_CODE)
                  
                  1 Reply Last reply Reply Quote 0
                  • C
                    chimntu @S2108014 last edited by

                    @James-Bond
                    Can we print name of the stock using this code? If yes, How?

                    S2108014 1 Reply Last reply Reply Quote 0
                    • S2108014
                      S2108014 @chimntu last edited by

                      @djdenish
                      No, we don't receive Scrip name in WebSocket response, but you can use this JSON file and pandas to fetch scrip name by filtering it by using token to get scrip name.

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

                        @James-Bond Please advise along with Bid / ask price, can we get the corresponding Qty for stocks/options

                        thanks in advance
                        Sukhwant

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