Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs
    1. Home
    2. nayan_nandi
    N
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    nayan_nandi

    @nayan_nandi

    0
    Reputation
    21
    Posts
    7
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    nayan_nandi Follow

    Best posts made by nayan_nandi

    This user hasn't posted anything yet.

    Latest posts made by nayan_nandi

    • Can't install smartapi python library using pip

      I'm trying to install python smartapi library using this command "pip install smartapi" but it's throw error like this...

      note: This error originates from a subprocess, and is likely not a problem with pip.
      error: legacy-install-failure

      × Encountered error while trying to install package.
      ╰─> PyCrypto

      note: This is an issue with the package mentioned above, not pip.
      hint: See above for output from the failure.

      gfhghfghfhfh.PNG
      And how cam I fix this issue...?

      posted in Python SDK
      N
      nayan_nandi
    • Is there need any aditional parameter to stream the F&O data???

      I want to stream this scripts' data___
      "64911": "TATAMOTORS29APR21FUT",
      "64719": "ITC29APR21FUT",
      "64815": "SAIL29APR21FUT"

      This is my code___

      from smartapi import SmartConnect
      from smartapi import WebSocket
      import creds
      
      obj = SmartConnect(api_key=creds.api_key)
      # print(obj)
      
      data = obj.generateSession(creds.client_token, creds.password)
      refreshToken = data['data']['refreshToken']
      # print(refreshToken)
      
      feedToken = obj.getfeedToken()
      # print(feedToken)
      
      userProfile = obj.getProfile(refreshToken)
      # print(userProfile)
      
      FEED_TOKEN = feedToken
      CLIENT_CODE = creds.client_token
      
      token = "nse_cm|64911&nse_cm|64719&nse_cm|64815"
      task = "mw"  # "mw"|"sfi"|"dp"
      
      ss = WebSocket(FEED_TOKEN, CLIENT_CODE)
      
      trading_portfolios = {"64911": "TATAMOTORS29APR21FUT",
                            "64719": "ITC29APR21FUT",
                            "64815": "SAIL29APR21FUT"}
      
      
      def on_tick(ws, tick):
          print(tick)
      
      
      def on_connect(ws, response):
          ws.websocket_connection()
          ws.send_request(token, task)
      
      
      # Assign the callbacks.
      ss.on_ticks = on_tick
      ss.on_connect = on_connect
      
      ss.connect()
      
      

      But when I trying to stream the data, it's printing something like this______
      fghgh.PNG

      posted in General Discussion
      N
      nayan_nandi
    • RE: How to map the token number with their symbol name?

      @rajanprabu Can anyone please tell me what is wrong with this code__

      token = "nse_cm|2885&nse_cm|3465&nse_cm|1660"
      task = "mw"  # "mw"|"sfi"|"dp"
      
      ss = WebSocket(FEED_TOKEN, CLIENT_CODE)
      
      trading_portfolio = {"nse_cm|2885": "RELIANCE", "nse_cm|3465": "TATAMOTORS", "nse_cm|1660": "ITC"}
      
      
      def on_tick(ws, tick):
          for single_company in tick:
              inst_of_single_company = single_company['tk']
              name = trading_portfolio[inst_of_single_company]
      
              print(single_company, name)
      

      I'm getting error like this____

      Unhandled Error
      Traceback (most recent call last):
        File "C:\Python 3.9.2\lib\site-packages\twisted\python\log.py", line 101, in callWithLogger
          return callWithContext({"system": lp}, func, *args, **kw)
        File "C:\Python 3.9.2\lib\site-packages\twisted\python\log.py", line 85, in callWithContext
          return context.call({ILogContext: newCtx}, func, *args, **kw)
        File "C:\Python 3.9.2\lib\site-packages\twisted\python\context.py", line 118, in callWithContext
          return self.currentContext().callWithContext(ctx, func, *args, **kw)
        File "C:\Python 3.9.2\lib\site-packages\twisted\python\context.py", line 83, in callWithContext
          return func(*args, **kw)
      --- <exception caught here> ---
        File "C:\Python 3.9.2\lib\site-packages\twisted\internet\selectreactor.py", line 149, in _doReadOrWrite
          why = getattr(selectable, method)()
        File "C:\Python 3.9.2\lib\site-packages\twisted\internet\tcp.py", line 246, in doRead
          return self._dataReceived(data)
        File "C:\Python 3.9.2\lib\site-packages\twisted\internet\tcp.py", line 251, in _dataReceived
          rval = self.protocol.dataReceived(data)
        File "C:\Python 3.9.2\lib\site-packages\twisted\protocols\tls.py", line 324, in dataReceived
          self._flushReceiveBIO()
        File "C:\Python 3.9.2\lib\site-packages\twisted\protocols\tls.py", line 290, in _flushReceiveBIO
          ProtocolWrapper.dataReceived(self, bytes)
        File "C:\Python 3.9.2\lib\site-packages\twisted\protocols\policies.py", line 107, in dataReceived
          self.wrappedProtocol.dataReceived(data)
        File "C:\Python 3.9.2\lib\site-packages\autobahn\twisted\websocket.py", line 290, in dataReceived
          self._dataReceived(data)
        File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1207, in _dataReceived
          self.consumeData()
        File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1219, in consumeData
          while self.processData() and self.state != WebSocketProtocol.STATE_CLOSED:
        File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1579, in processData
          fr = self.onFrameEnd()
        File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1704, in onFrameEnd
          self._onMessageEnd()
        File "C:\Python 3.9.2\lib\site-packages\autobahn\twisted\websocket.py", line 318, in _onMessageEnd
          self.onMessageEnd()
        File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 628, in onMessageEnd
          self._onMessage(payload, self.message_is_binary)
        File "C:\Python 3.9.2\lib\site-packages\autobahn\twisted\websocket.py", line 321, in _onMessage
          self.onMessage(payload, isBinary)
        File "C:\Python 3.9.2\lib\site-packages\smartapi\webSocket.py", line 41, in onMessage
          self.factory.on_message(self, payload, is_binary)
        File "C:\Python 3.9.2\lib\site-packages\smartapi\webSocket.py", line 337, in _on_message
          self._parse_text_message(payload)
        File "C:\Python 3.9.2\lib\site-packages\smartapi\webSocket.py", line 377, in _parse_text_message
          self.on_ticks(self, data)
        File "C:\Users\Nayan\PycharmProjects\Angel_Broking\main.py", line 31, in on_tick
          inst_of_single_company = single_company['tk']
      builtins.KeyError: 'tk'
      
      Unhandled Error
      Traceback (most recent call last):
        File "C:\Python 3.9.2\lib\site-packages\smartapi\webSocket.py", line 233, in connect
          reactor.run(**opts)
        File "C:\Python 3.9.2\lib\site-packages\twisted\internet\base.py", line 1423, in run
          self.mainLoop()
        File "C:\Python 3.9.2\lib\site-packages\twisted\internet\base.py", line 1436, in mainLoop
          reactorBaseSelf.doIteration(t)
        File "C:\Python 3.9.2\lib\site-packages\twisted\internet\selectreactor.py", line 143, in doSelect
          _logrun(selectable, _drdw, selectable, method)
      --- <exception caught here> ---
        File "C:\Python 3.9.2\lib\site-packages\twisted\python\log.py", line 101, in callWithLogger
          return callWithContext({"system": lp}, func, *args, **kw)
        File "C:\Python 3.9.2\lib\site-packages\twisted\python\log.py", line 85, in callWithContext
          return context.call({ILogContext: newCtx}, func, *args, **kw)
        File "C:\Python 3.9.2\lib\site-packages\twisted\python\context.py", line 118, in callWithContext
          return self.currentContext().callWithContext(ctx, func, *args, **kw)
        File "C:\Python 3.9.2\lib\site-packages\twisted\python\context.py", line 83, in callWithContext
          return func(*args, **kw)
        File "C:\Python 3.9.2\lib\site-packages\twisted\internet\selectreactor.py", line 154, in _doReadOrWrite
          self._disconnectSelectable(selectable, why, method == "doRead")
        File "C:\Python 3.9.2\lib\site-packages\twisted\internet\posixbase.py", line 306, in _disconnectSelectable
          selectable.connectionLost(failure.Failure(why))
        File "C:\Python 3.9.2\lib\site-packages\twisted\internet\tcp.py", line 506, in connectionLost
          self._commonConnection.connectionLost(self, reason)
        File "C:\Python 3.9.2\lib\site-packages\twisted\internet\tcp.py", line 324, in connectionLost
          protocol.connectionLost(reason)
        File "C:\Python 3.9.2\lib\site-packages\twisted\protocols\tls.py", line 389, in connectionLost
          self._flushReceiveBIO()
        File "C:\Python 3.9.2\lib\site-packages\twisted\protocols\tls.py", line 290, in _flushReceiveBIO
          ProtocolWrapper.dataReceived(self, bytes)
        File "C:\Python 3.9.2\lib\site-packages\twisted\protocols\policies.py", line 107, in dataReceived
          self.wrappedProtocol.dataReceived(data)
        File "C:\Python 3.9.2\lib\site-packages\autobahn\twisted\websocket.py", line 290, in dataReceived
          self._dataReceived(data)
        File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1207, in _dataReceived
          self.consumeData()
        File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1219, in consumeData
          while self.processData() and self.state != WebSocketProtocol.STATE_CLOSED:
        File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1571, in processData
          fr = self.onFrameData(payload)
        File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1666, in onFrameData
          self._onMessageFrameData(payload)
        File "C:\Python 3.9.2\lib\site-packages\autobahn\twisted\websocket.py", line 309, in _onMessageFrameData
          self.onMessageFrameData(payload)
        File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 602, in onMessageFrameData
          self.frame_data.append(payload)
      builtins.AttributeError: 'NoneType' object has no attribute 'append'
      
      posted in General Discussion
      N
      nayan_nandi
    • Facing problem when fetching the token list

      This is my code___

      import pandas as pd
      url = "https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json"
      df = pd.read_json(url)
      df.to_excel("Token_List.xlsx")
      print('DataFrame is written to Excel File successfully.')
      

      But when I search the symbol like_ TATAMOTORS, ITC
      TATAMOTORS.PNG
      ITC.PNG
      I think it's showing right.

      But, when I search the symbol like_ RELIANCE, TATAPOWER
      It's showing like this_____
      RELIANCE.PNG
      TATAPOWER.PNG
      Why it's happening.........

      posted in General Discussion
      N
      nayan_nandi
    • RE: How to map the token number with their symbol name?

      @rjbanna Yes Sir, but here has two type of response.

      [{'ap': '2031.81', 'bp': '2038.05', 'bq': '44', 'bs': '121', 'c': '2029.30', 'cng': '09.20', 'e': 'nse_cm', 'lo': '2011.60', 'ltp': '2038.50', 'ltq': '10', 'ltt': '31/03/2021 09:52:10', 'name': 'sf', 'nc': '00.45', 'sp': '2038.50', 'tbq': '319613', 'tk': '2885', 'to': '2680052885.07', 'tsq': '321701', 'v': '1319047'}] 
      
      
      [{'e': 'nse_cm', 'ltp': '2038.50', 'ltq': '25', 'ltt': 'NA', 'name': 'sf', 'tk': '2885'}] 
      

      So how can I select first one programmatically, not second one?

      posted in General Discussion
      N
      nayan_nandi
    • How to map the token number with their symbol name?

      How to map the token number with their symbol name?
      I have subscribe RELIANCE_EQ's token number.

      token = "nse_cm|2885"  # Token number of RELIANCE_EQ
      task = "mw"  # "mw"|"sfi"|"dp"
      

      And stream the WebSocket. It's perfectly works.

      [{'ak': 'ok', 'msg': 'heartbeat', 'task': 'hb'}] 
      
      [] 
      
      [{'e': 'nse_cm', 'ltp': '2038.50', 'ltq': '20', 'ltt': 'NA', 'name': 'sf', 'tk': '2885'}] 
      
      [{'name': 'tm', 'tvalue': '31/03/2021 09:52:10'}] 
      
      [{'ap': '2031.81', 'bp': '2038.05', 'bq': '44', 'bs': '121', 'c': '2029.30', 'cng': '09.20', 'e': 'nse_cm', 'lo': '2011.60', 'ltp': '2038.50', 'ltq': '10', 'ltt': '31/03/2021 09:52:10', 'name': 'sf', 'nc': '00.45', 'sp': '2038.50', 'tbq': '319613', 'tk': '2885', 'to': '2680052885.07', 'tsq': '321701', 'v': '1319047'}] 
      
      [{'e': 'nse_cm', 'ltp': '2038.50', 'ltq': '25', 'ltt': 'NA', 'name': 'sf', 'tk': '2885'}] 
      
      [{'name': 'tm', 'tvalue': '31/03/2021 09:52:11'}] 
      
      [{'ap': '2031.81', 'bp': '2038.00', 'bq': '291', 'bs': '23', 'c': '2029.30', 'cng': '09.20', 'e': 'nse_cm', 'lo': '2011.60', 'ltp': '2038.50', 'ltq': '2', 'ltt': '31/03/2021 09:52:11', 'name': 'sf', 'nc': '00.45', 'sp': '2038.50', 'tbq': '320028', 'tk': '2885', 'to': '2680540519.47', 'tsq': '321777', 'v': '1319287'}] 
      
      [{'e': 'nse_cm', 'ltp': '2038.50', 'ltq': '2', 'ltt': 'NA', 'name': 'sf', 'tk': '2885'}] 
      
      [{'name': 'tm', 'tvalue': '31/03/2021 09:52:12'}] 
      
      [{'ap': '2031.81', 'bp': '2038.05', 'bq': '161', 'bs': '12', 'c': '2029.30', 'cng': '09.20', 'e': 'nse_cm', 'lo': '2011.60', 'ltp': '2038.50', 'ltq': '6', 'ltt': '31/03/2021 09:52:12', 'name': 'sf', 'nc': '00.45', 'sp': '2038.50', 'tbq': '320288', 'tk': '2885', 'to': '2680570996.62', 'tsq': '321742', 'v': '1319302'}] 
      

      But the problem is it's showing messy especially when we subscribe multiple tokens. So how can we map the token number with their symbol name and display that like this__

      RELIANCE_EQ:- tk: 2885, ltp:2038.50, to: 2680570996.62
      

      Can anyone please give any idea to do that.......

      posted in General Discussion
      N
      nayan_nandi
    • RE: Facing problem when streaming the live data

      @rajanprabu Thank sir I was missing this code, thanks for your help sir.......

      posted in General Discussion
      N
      nayan_nandi
    • RE: Facing problem when streaming the live data

      @admin Sir I did but sowing same thing____

      "C:\Python 3.9.2\python.exe" C:/Users/Nayan/PycharmProjects/Angel_Broking/main.py
      None
      <function on_connect at 0x00000026BF9B7F70>
      Ticks: [{'ak': 'nk', 'msg': 'mw', 'task': 'mw'}]
      
      Process finished with exit code -1
      

      I'm using trading api.....

      posted in General Discussion
      N
      nayan_nandi
    • RE: Facing problem when streaming the live data

      @admin How can i do it sir??

      posted in General Discussion
      N
      nayan_nandi
    • RE: Facing problem when streaming the live data

      @admin So sir why i'm not getting feed. also when i trying to print feedToken it's show None what can i do.....
      This is my code______

      from smartapi import SmartConnect
      from smartapi import WebSocket
      import creds
      
      obj = SmartConnect(api_key=creds.api_key)
      data = obj.generateSession(creds.client_token, creds.password)
      feedToken = obj.getfeedToken()
      
      print(feedToken)
      
      FEED_TOKEN = feedToken
      CLIENT_CODE = creds.client_token
      
      token = "nse_cm|2885"  # Token number of RELIANCE-EQ
      task = "mw"  # 'mw'|'sfi'|'dp'
      ss = WebSocket(FEED_TOKEN, CLIENT_CODE)
      
      
      def on_tick(ws, tick):
          print("Ticks: {}".format(tick))
      
      
      def on_connect(ws, response):
          ws.send_request(token, task)
      
      
      # def on_close(ws, code, reason):
      #     ws.stop()
      
      
      ss.on_ticks = on_tick
      ss.on_connect = on_connect
      # ss.on_close = on_close
      
      ss.connect()
      
      
      posted in General Discussion
      N
      nayan_nandi